@loaders.gl/tile-converter 4.0.0-alpha.6 → 4.0.0-alpha.7

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/bin/converter.js +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -2
  3. package/dist/3d-tiles-attributes-worker.js.map +3 -3
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/3d-tiles-converter.js +4 -3
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +0 -8
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +2 -15
  9. package/dist/converter.min.js +75 -76
  10. package/dist/deps-installer/deps-installer.js +3 -3
  11. package/dist/dist.min.js +1870 -1581
  12. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  13. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +0 -3
  14. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  15. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +2 -10
  16. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  17. package/dist/es5/deps-installer/deps-installer.js +4 -4
  18. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  19. package/dist/es5/i3s-attributes-worker.js +1 -1
  20. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  21. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +2 -2
  22. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-converter.js +25 -17
  24. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +1 -4
  26. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  27. package/dist/es5/i3s-converter/i3s-converter.js +0 -7
  28. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  29. package/dist/es5/lib/utils/geometry-utils.js +15 -0
  30. package/dist/es5/lib/utils/geometry-utils.js.map +1 -0
  31. package/dist/es5/pgm-loader.js +1 -1
  32. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  33. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +0 -3
  34. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  35. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +2 -8
  36. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  37. package/dist/esm/deps-installer/deps-installer.js +4 -4
  38. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  39. package/dist/esm/i3s-attributes-worker.js +1 -1
  40. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  41. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +2 -2
  42. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  43. package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -11
  44. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  45. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +1 -4
  46. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  47. package/dist/esm/i3s-converter/i3s-converter.js +0 -7
  48. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  49. package/dist/esm/lib/utils/geometry-utils.js +8 -0
  50. package/dist/esm/lib/utils/geometry-utils.js.map +1 -0
  51. package/dist/esm/pgm-loader.js +1 -1
  52. package/dist/i3s-attributes-worker.d.ts +10 -2
  53. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  54. package/dist/i3s-attributes-worker.js +2 -2
  55. package/dist/i3s-attributes-worker.js.map +3 -3
  56. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +4 -2
  57. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  58. package/dist/i3s-converter/helpers/batch-ids-extensions.js +2 -2
  59. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  60. package/dist/i3s-converter/helpers/geometry-converter.js +51 -43
  61. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  62. package/dist/i3s-converter/helpers/gltf-attributes.js +1 -4
  63. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  64. package/dist/i3s-converter/i3s-converter.js +7 -6
  65. package/dist/lib/utils/geometry-utils.d.ts +9 -0
  66. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  67. package/dist/lib/utils/geometry-utils.js +18 -0
  68. package/package.json +15 -16
  69. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -3
  70. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +2 -16
  71. package/src/deps-installer/deps-installer.ts +3 -3
  72. package/src/i3s-attributes-worker.ts +11 -2
  73. package/src/i3s-converter/helpers/batch-ids-extensions.ts +13 -14
  74. package/src/i3s-converter/helpers/geometry-converter.ts +105 -78
  75. package/src/i3s-converter/helpers/gltf-attributes.ts +1 -4
  76. package/src/i3s-converter/i3s-converter.ts +8 -7
  77. package/src/lib/utils/geometry-utils.ts +14 -0
@@ -1,10 +1,10 @@
1
1
  import type {B3DMContent, FeatureTableJson} from '@loaders.gl/3d-tiles';
2
2
  import type {
3
3
  GLTF_EXT_feature_metadata,
4
+ GLTF_EXT_mesh_features,
4
5
  GLTFAccessorPostprocessed,
5
6
  GLTFMaterialPostprocessed,
6
7
  GLTFNodePostprocessed,
7
- GLTFImagePostprocessed,
8
8
  GLTFMeshPrimitivePostprocessed,
9
9
  GLTFMeshPostprocessed,
10
10
  GLTFTexturePostprocessed
@@ -33,14 +33,16 @@ import {
33
33
  MaterialDefinitionInfo,
34
34
  TextureDefinitionInfo
35
35
  } from '@loaders.gl/i3s';
36
- import {TypedArray} from '@loaders.gl/schema';
36
+ import {NumberArray, TypedArray} from '@loaders.gl/loader-utils';
37
37
  import {Geoid} from '@math.gl/geoid';
38
38
  /** Usage of worker here brings more overhead than advantage */
39
- import {B3DMAttributesData /*, transformI3SAttributesOnWorker*/} from '../../i3s-attributes-worker';
39
+ import {
40
+ B3DMAttributesData /*, transformI3SAttributesOnWorker*/,
41
+ TextureImageProperties
42
+ } from '../../i3s-attributes-worker';
40
43
  import {prepareDataForAttributesConversion} from './gltf-attributes';
41
44
  import {handleBatchIdsExtensions} from './batch-ids-extensions';
42
45
  import {checkPropertiesLength, flattenPropertyTableByFeatureIds} from './feature-attributes';
43
- import {MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';
44
46
  import {GL} from '@loaders.gl/math';
45
47
 
46
48
  /*
@@ -49,6 +51,7 @@ import {GL} from '@loaders.gl/math';
49
51
  import type {TypedArrayConstructor} from '@math.gl/types';
50
52
  */
51
53
  import type {TypedArrayConstructor} from '../types';
54
+ import {generateSyntheticIndices} from '../../lib/utils/geometry-utils';
52
55
 
53
56
  // Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/pbrMetallicRoughness.cmn.md
54
57
  const DEFAULT_ROUGHNESS_FACTOR = 1;
@@ -376,7 +379,7 @@ export async function convertAttributes(
376
379
  */
377
380
  function convertNodes(
378
381
  nodes: GLTFNodePostprocessed[],
379
- images: GLTFImagePostprocessed[],
382
+ images: (TextureImageProperties | null)[],
380
383
  cartographicOrigin: Vector3,
381
384
  cartesianModelMatrix: Matrix4,
382
385
  attributesMap: Map<string, ConvertedAttributes>,
@@ -442,7 +445,7 @@ function getCompositeTransformationMatrix(node: GLTFNodePostprocessed, matrix: M
442
445
  */
443
446
  function convertNode(
444
447
  node: GLTFNodePostprocessed,
445
- images: GLTFImagePostprocessed[],
448
+ images: (TextureImageProperties | null)[],
446
449
  cartographicOrigin: Vector3,
447
450
  cartesianModelMatrix: Matrix4,
448
451
  attributesMap: Map<string, ConvertedAttributes>,
@@ -493,7 +496,7 @@ function convertNode(
493
496
  */
494
497
  function convertMesh(
495
498
  mesh: GLTFMeshPostprocessed,
496
- images: GLTFImagePostprocessed[],
499
+ images: (TextureImageProperties | null)[],
497
500
  cartographicOrigin: Vector3,
498
501
  cartesianModelMatrix: Matrix4,
499
502
  attributesMap: Map<string, ConvertedAttributes>,
@@ -504,20 +507,24 @@ function convertMesh(
504
507
  let outputAttributes: ConvertedAttributes | null | undefined = null;
505
508
  let materialUvRegion: Uint16Array | undefined;
506
509
  if (primitive.material) {
507
- outputAttributes = attributesMap.get(primitive.material.uniqueId);
510
+ outputAttributes = attributesMap.get(primitive.material.id);
508
511
  materialUvRegion = outputAttributes?.mergedMaterials.find(
509
- ({originalMaterialId}) => originalMaterialId === primitive.material?.uniqueId
512
+ ({originalMaterialId}) => originalMaterialId === primitive.material?.id
510
513
  )?.uvRegion;
511
514
  } else if (attributesMap.has('default')) {
512
515
  outputAttributes = attributesMap.get('default');
513
516
  }
514
517
  assert(outputAttributes !== null, 'Primitive - material mapping failed');
518
+ assert(
519
+ primitive.mode === GL.TRIANGLES || primitive.mode === GL.TRIANGLE_STRIP,
520
+ `Primitive - unsupported mode ${primitive.mode}`
521
+ );
515
522
  const attributes = primitive.attributes;
516
523
  if (!outputAttributes) {
517
524
  continue;
518
525
  }
519
526
 
520
- const indices = getIndices(primitive);
527
+ const indices = normalizeIndices(primitive);
521
528
  outputAttributes.positions = concatenateTypedArrays(
522
529
  outputAttributes.positions,
523
530
  transformVertexArray({
@@ -567,11 +574,16 @@ function convertMesh(
567
574
  }
568
575
  /**
569
576
  * Converts TRIANGLE-STRIPS to independent TRIANGLES
570
- * @param {MeshPrimitive} primitive - the primitive to get the indices from
577
+ * @param primitive - the primitive to get the indices from
571
578
  * @returns indices of vertices of the independent triangles
572
579
  */
573
- function getIndices(primitive: MeshPrimitive): TypedArray {
574
- let indices: TypedArray = primitive.indices?.value;
580
+ function normalizeIndices(primitive: GLTFMeshPrimitivePostprocessed): TypedArray {
581
+ let indices: TypedArray | undefined = primitive.indices?.value;
582
+ if (!indices) {
583
+ const positions = primitive.attributes.POSITION.value;
584
+ return generateSyntheticIndices(positions.length / VALUES_PER_VERTEX);
585
+ }
586
+
575
587
  if (indices && primitive.mode === GL.TRIANGLE_STRIP) {
576
588
  /*
577
589
  TRIANGLE_STRIP geometry contains n+2 vertices for n triangles;
@@ -600,7 +612,7 @@ function getIndices(primitive: MeshPrimitive): TypedArray {
600
612
  }
601
613
  indices = newIndices;
602
614
  }
603
- return indices;
615
+ return indices as TypedArray;
604
616
  }
605
617
 
606
618
  /**
@@ -613,17 +625,17 @@ function getIndices(primitive: MeshPrimitive): TypedArray {
613
625
  * @param args.indices - gltf primitive indices
614
626
  * @param args.attributeSpecificTransformation - function to do attribute - specific transformations
615
627
  * @param args.useCartesianPositions - use coordinates as it is.
616
- * @returns {Float32Array}
628
+ * @returns
617
629
  */
618
630
  function transformVertexArray(args: {
619
- vertices: Float32Array;
631
+ vertices: TypedArray;
620
632
  cartographicOrigin: number[];
621
633
  cartesianModelMatrix: number[];
622
634
  nodeMatrix: Matrix4;
623
635
  indices: TypedArray;
624
636
  attributeSpecificTransformation: Function;
625
637
  useCartesianPositions: boolean;
626
- }) {
638
+ }): Float32Array {
627
639
  const {vertices, indices, attributeSpecificTransformation} = args;
628
640
  const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
629
641
  if (!vertices) {
@@ -699,7 +711,7 @@ function transformVertexNormals(vertexVector, calleeArgs): number[] {
699
711
  * @param indices - gltf primitive indices
700
712
  * @returns flattened texture coordinates
701
713
  */
702
- function flattenTexCoords(texCoords: Float32Array, indices: TypedArray): Float32Array {
714
+ function flattenTexCoords(texCoords: TypedArray, indices: TypedArray): Float32Array {
703
715
  const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
704
716
  if (!texCoords) {
705
717
  // We need dummy UV0s because it is required in 1.6
@@ -766,7 +778,7 @@ function createUvRegion(materialUvRegion: Uint16Array, indices: TypedArray): Uin
766
778
  * @param indices - gltf primitive indices
767
779
  * @returns flattened batch ids
768
780
  */
769
- function flattenBatchIds(batchedIds: number[], indices: TypedArray): number[] {
781
+ function flattenBatchIds(batchedIds: NumberArray, indices: TypedArray): number[] {
770
782
  if (!batchedIds.length || !indices.length) {
771
783
  return [];
772
784
  }
@@ -789,9 +801,9 @@ function getBatchIds(
789
801
  [key: string]: GLTFAccessorPostprocessed;
790
802
  },
791
803
  primitive: GLTFMeshPrimitivePostprocessed,
792
- images: GLTFImagePostprocessed[]
793
- ): number[] {
794
- const batchIds: number[] = handleBatchIdsExtensions(attributes, primitive, images);
804
+ images: (TextureImageProperties | null)[]
805
+ ): NumberArray {
806
+ const batchIds: NumberArray = handleBatchIdsExtensions(attributes, primitive, images);
795
807
 
796
808
  if (batchIds.length) {
797
809
  return batchIds;
@@ -979,9 +991,8 @@ function convertMaterial(sourceMaterial: GLTFMaterialPostprocessed): I3SMaterial
979
991
  };
980
992
  }
981
993
 
982
- const uniqueId = uuidv4();
983
- sourceMaterial.uniqueId = uniqueId;
984
- let mergedMaterials: MergedMaterial[] = [{originalMaterialId: uniqueId}];
994
+ sourceMaterial.id = Number.isFinite(sourceMaterial.id) ? sourceMaterial.id : uuidv4();
995
+ let mergedMaterials: MergedMaterial[] = [{originalMaterialId: sourceMaterial.id}];
985
996
  if (!texture) {
986
997
  // Should use default baseColorFactor if it is not present in source material
987
998
  // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-pbrmetallicroughness
@@ -1167,7 +1178,7 @@ function extractSharedResourcesTextureInfo(
1167
1178
  // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/image.cmn.md
1168
1179
  id: generateImageId(texture, nodeId),
1169
1180
  size: texture.source?.image.width,
1170
- length: [texture.source?.image.data.length]
1181
+ length: texture.source?.image.data.length ? [texture.source?.image.data.length] : undefined
1171
1182
  }
1172
1183
  ]
1173
1184
  };
@@ -1181,7 +1192,10 @@ function extractSharedResourcesTextureInfo(
1181
1192
  * @returns calculate image ID according to the spec
1182
1193
  */
1183
1194
  function generateImageId(texture: GLTFTexturePostprocessed, nodeId: number) {
1184
- const {width, height} = texture.source?.image;
1195
+ const {width, height} = texture.source?.image || {};
1196
+ if (!width || !height) {
1197
+ return '';
1198
+ }
1185
1199
  const levelCountOfTexture = 1;
1186
1200
  const indexOfLevel = 0;
1187
1201
  const indexOfTextureInStore = nodeId + 1;
@@ -1220,13 +1234,17 @@ function makeFeatureIdsUnique(
1220
1234
 
1221
1235
  /**
1222
1236
  * Generate replace map to make featureIds unique.
1223
- * @param {Array} featureIds
1224
- * @param {Object} batchTable
1225
- * @param {Array} featuresHashArray
1226
- * @returns {Object}
1237
+ * @param featureIds
1238
+ * @param batchTable
1239
+ * @param featuresHashArray
1240
+ * @returns
1227
1241
  */
1228
- function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
1229
- const featureMap = {};
1242
+ function getFeaturesReplaceMap(
1243
+ featureIds: any[],
1244
+ batchTable: object,
1245
+ featuresHashArray: any[]
1246
+ ): Record<string, any> {
1247
+ const featureMap: Record<string, any> = {};
1230
1248
 
1231
1249
  for (let index = 0; index < featureIds.length; index++) {
1232
1250
  const oldFeatureId = featureIds[index];
@@ -1239,11 +1257,11 @@ function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
1239
1257
 
1240
1258
  /**
1241
1259
  * Generates string for unique batch id creation.
1242
- * @param {Object} batchTable
1243
- * @param {Number} index
1244
- * @returns {String}
1260
+ * @param batchTable
1261
+ * @param index
1262
+ * @returns
1245
1263
  */
1246
- function generateStringFromBatchTableByIndex(batchTable, index) {
1264
+ function generateStringFromBatchTableByIndex(batchTable: object, index: number): string {
1247
1265
  let str = '';
1248
1266
  for (const key in batchTable) {
1249
1267
  str += batchTable[key][index];
@@ -1253,12 +1271,16 @@ function generateStringFromBatchTableByIndex(batchTable, index) {
1253
1271
 
1254
1272
  /**
1255
1273
  * Return already exited featureId or creates and returns new to support unique feature ids throw nodes.
1256
- * @param {Number} index
1257
- * @param {Object} batchTable
1258
- * @param {Array} featuresHashArray
1259
- * @returns {Number}
1274
+ * @param index
1275
+ * @param batchTable
1276
+ * @param featuresHashArray
1277
+ * @returns
1260
1278
  */
1261
- function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
1279
+ function getOrCreateUniqueFeatureId(
1280
+ index: number,
1281
+ batchTable: object,
1282
+ featuresHashArray: any[]
1283
+ ): number {
1262
1284
  const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
1263
1285
  const hash = md5(batchTableStr);
1264
1286
 
@@ -1270,11 +1292,11 @@ function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
1270
1292
 
1271
1293
  /**
1272
1294
  * Do replacement of indices for making them unique through all nodes.
1273
- * @param {Array} indicesArray
1274
- * @param {Object} featureMap
1275
- * @returns {void}
1295
+ * @param indicesArray
1296
+ * @param featureMap
1297
+ * @returns
1276
1298
  */
1277
- function replaceIndicesByUnique(indicesArray, featureMap) {
1299
+ function replaceIndicesByUnique(indicesArray: any[], featureMap: Record<string, []>) {
1278
1300
  for (let index = 0; index < indicesArray.length; index++) {
1279
1301
  indicesArray[index] = featureMap[indicesArray[index]];
1280
1302
  }
@@ -1282,16 +1304,16 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
1282
1304
 
1283
1305
  /**
1284
1306
  * Convert property table data to attribute buffers.
1285
- * @param {Array} featureIds
1286
- * @param {Object} propertyTable - table with metadata for particular feature.
1287
- * @param {Array} attributeStorageInfo
1288
- * @returns {Array} - Array of file buffers.
1307
+ * @param featureIds
1308
+ * @param propertyTable - table with metadata for particular feature.
1309
+ * @param attributeStorageInfo
1310
+ * @returns - Array of file buffers.
1289
1311
  */
1290
1312
  function convertPropertyTableToAttributeBuffers(
1291
1313
  featureIds: number[],
1292
1314
  propertyTable: FeatureTableJson,
1293
1315
  attributeStorageInfo: AttributeStorageInfo[]
1294
- ) {
1316
+ ): any[] {
1295
1317
  const attributeBuffers: ArrayBuffer[] = [];
1296
1318
 
1297
1319
  const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);
@@ -1343,21 +1365,21 @@ function generateAttributeBuffer(type: string, value: any): ArrayBuffer {
1343
1365
 
1344
1366
  /**
1345
1367
  * Return attribute type.
1346
- * @param {String} key
1347
- * @param {Array} attributeStorageInfo
1348
- * @returns {String} attribute type.
1368
+ * @param key
1369
+ * @param attributeStorageInfo
1370
+ * @returns attribute type.
1349
1371
  */
1350
- function getAttributeType(key, attributeStorageInfo) {
1372
+ function getAttributeType(key: string, attributeStorageInfo: any[]): string {
1351
1373
  const attribute = attributeStorageInfo.find((attr) => attr.name === key);
1352
1374
  return attribute.attributeValues.valueType;
1353
1375
  }
1354
1376
 
1355
1377
  /**
1356
1378
  * Convert short integer to attribute arrayBuffer.
1357
- * @param {Array} featureIds
1358
- * @returns {ArrayBuffer} - Buffer with objectId data.
1379
+ * @param featureIds
1380
+ * @returns - Buffer with objectId data.
1359
1381
  */
1360
- function generateShortIntegerAttributeBuffer(featureIds): ArrayBuffer {
1382
+ function generateShortIntegerAttributeBuffer(featureIds: any[]): ArrayBuffer {
1361
1383
  const count = new Uint32Array([featureIds.length]);
1362
1384
  const valuesArray = new Uint32Array(featureIds);
1363
1385
  return concatenateArrayBuffers(count.buffer, valuesArray.buffer);
@@ -1365,10 +1387,10 @@ function generateShortIntegerAttributeBuffer(featureIds): ArrayBuffer {
1365
1387
 
1366
1388
  /**
1367
1389
  * Convert double to attribute arrayBuffer.
1368
- * @param {Array} featureIds
1369
- * @returns {ArrayBuffer} - Buffer with objectId data.
1390
+ * @param featureIds
1391
+ * @returns - Buffer with objectId data.
1370
1392
  */
1371
- function generateDoubleAttributeBuffer(featureIds): ArrayBuffer {
1393
+ function generateDoubleAttributeBuffer(featureIds: any[]): ArrayBuffer {
1372
1394
  const count = new Uint32Array([featureIds.length]);
1373
1395
  const padding = new Uint8Array(4);
1374
1396
  const valuesArray = new Float64Array(featureIds);
@@ -1378,10 +1400,10 @@ function generateDoubleAttributeBuffer(featureIds): ArrayBuffer {
1378
1400
 
1379
1401
  /**
1380
1402
  * Convert batch table attributes to array buffer with batch table data.
1381
- * @param {Array} batchAttributes
1382
- * @returns {ArrayBuffer} - Buffer with batch table data.
1403
+ * @param batchAttributes
1404
+ * @returns - Buffer with batch table data.
1383
1405
  */
1384
- function generateStringAttributeBuffer(batchAttributes): ArrayBuffer {
1406
+ function generateStringAttributeBuffer(batchAttributes: any[]): ArrayBuffer {
1385
1407
  const stringCountArray = new Uint32Array([batchAttributes.length]);
1386
1408
  let totalNumberOfBytes = 0;
1387
1409
  const stringSizesArray = new Uint32Array(batchAttributes.length);
@@ -1408,10 +1430,10 @@ function generateStringAttributeBuffer(batchAttributes): ArrayBuffer {
1408
1430
 
1409
1431
  /**
1410
1432
  * Convert featureIds to BigUint64Array.
1411
- * @param {Array} featureIds
1412
- * @returns {BigUint64Array} - Array of feature ids in BigUint64 format.
1433
+ * @param featureIds
1434
+ * @returns - Array of feature ids in BigUint64 format.
1413
1435
  */
1414
- function generateBigUint64Array(featureIds) {
1436
+ function generateBigUint64Array(featureIds: any[]): BigUint64Array {
1415
1437
  const typedFeatureIds = new BigUint64Array(featureIds.length);
1416
1438
  for (let index = 0; index < featureIds.length; index++) {
1417
1439
  typedFeatureIds[index] = BigInt(featureIds[index]);
@@ -1428,11 +1450,11 @@ function generateBigUint64Array(featureIds) {
1428
1450
  * @returns {Promise<object>} - COmpressed geometry.
1429
1451
  */
1430
1452
  async function generateCompressedGeometry(
1431
- vertexCount,
1432
- convertedAttributes,
1433
- attributes,
1434
- dracoWorkerSoure
1435
- ) {
1453
+ vertexCount: number,
1454
+ convertedAttributes: Record<string, any>,
1455
+ attributes: Record<string, any>,
1456
+ dracoWorkerSoure: string
1457
+ ): Promise<ArrayBuffer> {
1436
1458
  const {positions, normals, texCoords, colors, uvRegions, featureIds, faceRange} = attributes;
1437
1459
  const indices = new Uint32Array(vertexCount);
1438
1460
 
@@ -1492,11 +1514,14 @@ async function generateCompressedGeometry(
1492
1514
 
1493
1515
  /**
1494
1516
  * Generates ordered feature indices based on face range
1495
- * @param {Uint32Array} featureIndex
1496
- * @param {Uint32Array} faceRange
1497
- * @returns {Uint32Array}
1517
+ * @param featureIndex
1518
+ * @param faceRange
1519
+ * @returns
1498
1520
  */
1499
- function generateFeatureIndexAttribute(featureIndex, faceRange) {
1521
+ function generateFeatureIndexAttribute(
1522
+ featureIndex: Uint32Array,
1523
+ faceRange: Uint32Array
1524
+ ): Uint32Array {
1500
1525
  const orderedFeatureIndices = new Uint32Array(featureIndex.length);
1501
1526
  let fillIndex = 0;
1502
1527
  let startIndex = 0;
@@ -1534,7 +1559,7 @@ export function getPropertyTable(tileContent: B3DMContent): FeatureTableJson | n
1534
1559
  return null;
1535
1560
  }
1536
1561
  case EXT_FEATURE_METADATA: {
1537
- return getPropertyTableFromExtFeatureMetadata(extension);
1562
+ return getPropertyTableFromExtFeatureMetadata(extension as GLTF_EXT_feature_metadata);
1538
1563
  }
1539
1564
  default:
1540
1565
  return null;
@@ -1545,7 +1570,9 @@ export function getPropertyTable(tileContent: B3DMContent): FeatureTableJson | n
1545
1570
  * Check extensions which can be with property table inside.
1546
1571
  * @param sourceTile
1547
1572
  */
1548
- function getPropertyTableExtension(tileContent: B3DMContent) {
1573
+ function getPropertyTableExtension(
1574
+ tileContent: B3DMContent
1575
+ ): GLTF_EXT_feature_metadata | GLTF_EXT_mesh_features {
1549
1576
  const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
1550
1577
  const extensionsUsed = tileContent?.gltf?.extensionsUsed;
1551
1578
 
@@ -38,10 +38,7 @@ export function prepareDataForAttributesConversion(tileContent: B3DMContent): B3
38
38
  tileContent.gltf?.images?.map((imageObject) => {
39
39
  // Need data only for uncompressed images because we can't get batchIds from compressed textures.
40
40
  if (imageObject?.image?.compressed) {
41
- return {
42
- data: null,
43
- compressed: true
44
- };
41
+ return null;
45
42
  } else {
46
43
  const data = imageObject?.image?.data;
47
44
  const dataCopy = new Uint8Array(data.length);
@@ -218,12 +218,13 @@ export default class I3SConverter {
218
218
  loadOptions: {
219
219
  _nodeWorkers: true,
220
220
  reuseWorkers: true,
221
- basis: {format: 'rgba32'},
222
- 'basis-nodejs': {
223
- format: 'rgba32',
224
- workerUrl: './modules/textures/dist/basis-nodejs-worker.js'
225
- },
226
- 'draco-nodejs': {workerUrl: './modules/draco/dist/draco-nodejs-worker.js'}
221
+ basis: {format: 'rgba32'}
222
+ // TODO - should no longer be needed with new Node workers
223
+ // 'basis-nodejs': {
224
+ // format: 'rgba32',
225
+ // workerUrl: './modules/textures/dist/basis-worker-node.js'
226
+ // },
227
+ // 'draco-nodejs': {workerUrl: './modules/draco/dist/draco-worker-node.js'}
227
228
  }
228
229
  };
229
230
  if (preloadOptions.headers) {
@@ -910,7 +911,7 @@ export default class I3SConverter {
910
911
  * @param slpkChildPath
911
912
  */
912
913
  private async writeTextureFile(
913
- textureData: Promise<ArrayBuffer>,
914
+ textureData: Uint8Array | Promise<ArrayBuffer>,
914
915
  name: string,
915
916
  format: 'jpg' | 'png' | 'ktx2',
916
917
  childPath: string,
@@ -0,0 +1,14 @@
1
+ /**
2
+ * luma.gl can not work without indices now:
3
+ * https://github.com/visgl/luma.gl/blob/d8cad75b9f8ca3e578cf078ed9d19e619c2ddbc9/modules/experimental/src/gltf/gltf-instantiator.js#L115
4
+ * This method generates syntetic indices array: [0, 1, 2, 3, .... , vertexCount-1]
5
+ * @param {number} vertexCount - vertex count in the geometry
6
+ * @returns {Uint32Array} indices array.
7
+ */
8
+ export const generateSyntheticIndices = (vertexCount: number): Uint32Array => {
9
+ const result = new Uint32Array(vertexCount);
10
+ for (let index = 0; index < vertexCount; index++) {
11
+ result[index] = index;
12
+ }
13
+ return result;
14
+ };