@loaders.gl/3d-tiles 4.0.0-alpha.7 → 4.0.0-alpha.9

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 (114) hide show
  1. package/dist/dist.min.js +317 -146
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js +4 -3
  4. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -1
  5. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js +2 -2
  6. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -1
  7. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  8. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +30 -18
  9. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  10. package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -1
  11. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js +12 -12
  12. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -1
  13. package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js.map +1 -1
  14. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +1 -1
  15. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +19 -4
  17. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  18. package/dist/es5/lib/parsers/parse-3d-tile-header.js +98 -80
  19. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
  20. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js +12 -21
  21. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
  22. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +29 -5
  23. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  24. package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
  25. package/dist/es5/lib/utils/version.js +1 -1
  26. package/dist/es5/tiles-3d-loader.js +26 -31
  27. package/dist/es5/tiles-3d-loader.js.map +1 -1
  28. package/dist/es5/types.js.map +1 -1
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js +3 -3
  31. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -1
  32. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js +2 -2
  33. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -1
  34. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  35. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +15 -9
  36. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  37. package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -1
  38. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js +7 -7
  39. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -1
  40. package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js.map +1 -1
  41. package/dist/esm/lib/parsers/parse-3d-tile-composite.js +1 -1
  42. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  43. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +15 -7
  44. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  45. package/dist/esm/lib/parsers/parse-3d-tile-header.js +62 -45
  46. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
  47. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js +12 -21
  48. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
  49. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +23 -2
  50. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  51. package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
  52. package/dist/esm/lib/utils/version.js +1 -1
  53. package/dist/esm/tiles-3d-loader.js +18 -12
  54. package/dist/esm/tiles-3d-loader.js.map +1 -1
  55. package/dist/esm/types.js.map +1 -1
  56. package/dist/index.d.ts +2 -1
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +4 -2
  59. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  60. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +3 -3
  61. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +3 -2
  62. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  63. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +2 -2
  64. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  65. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +5 -2
  66. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  67. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +15 -9
  68. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +2 -1
  69. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  70. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +4 -2
  71. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  72. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +7 -7
  73. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +4 -1
  74. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  75. package/dist/lib/parsers/parse-3d-tile-batched-model.js +1 -1
  76. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +3 -2
  77. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  78. package/dist/lib/parsers/parse-3d-tile-composite.js +1 -1
  79. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -1
  80. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  81. package/dist/lib/parsers/parse-3d-tile-gltf.js +13 -5
  82. package/dist/lib/parsers/parse-3d-tile-header.d.ts +5 -6
  83. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  84. package/dist/lib/parsers/parse-3d-tile-header.js +57 -42
  85. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -1
  86. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  87. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +11 -25
  88. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +3 -2
  89. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  90. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +23 -2
  91. package/dist/lib/parsers/parse-3d-tile.d.ts +4 -1
  92. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  93. package/dist/lib/parsers/parse-3d-tile.js +0 -4
  94. package/dist/tiles-3d-loader.d.ts.map +1 -1
  95. package/dist/tiles-3d-loader.js +18 -17
  96. package/dist/types.d.ts +257 -15
  97. package/dist/types.d.ts.map +1 -1
  98. package/package.json +8 -8
  99. package/src/index.ts +12 -1
  100. package/src/lib/parsers/helpers/normalize-3d-tile-colors.ts +10 -4
  101. package/src/lib/parsers/helpers/normalize-3d-tile-normals.ts +7 -3
  102. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +4 -4
  103. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +35 -13
  104. package/src/lib/parsers/helpers/parse-3d-tile-header.ts +7 -1
  105. package/src/lib/parsers/helpers/parse-3d-tile-tables.ts +32 -11
  106. package/src/lib/parsers/parse-3d-tile-batched-model.ts +18 -3
  107. package/src/lib/parsers/parse-3d-tile-composite.ts +7 -6
  108. package/src/lib/parsers/parse-3d-tile-gltf.ts +16 -8
  109. package/src/lib/parsers/parse-3d-tile-header.ts +84 -52
  110. package/src/lib/parsers/parse-3d-tile-instanced-model.ts +24 -33
  111. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +51 -19
  112. package/src/lib/parsers/parse-3d-tile.ts +10 -5
  113. package/src/tiles-3d-loader.ts +21 -23
  114. package/src/types.ts +269 -15
package/dist/dist.min.js CHANGED
@@ -6922,24 +6922,24 @@
6922
6922
  var TILE_REFINEMENT, TILE_TYPE, TILESET_TYPE, LOD_METRIC_TYPE;
6923
6923
  var init_constants3 = __esm({
6924
6924
  "../tiles/src/constants.ts"() {
6925
- TILE_REFINEMENT = {
6926
- ADD: 1,
6927
- REPLACE: 2
6928
- };
6929
- TILE_TYPE = {
6930
- EMPTY: "empty",
6931
- SCENEGRAPH: "scenegraph",
6932
- POINTCLOUD: "pointcloud",
6933
- MESH: "mesh"
6934
- };
6935
- TILESET_TYPE = {
6936
- I3S: "I3S",
6937
- TILES3D: "TILES3D"
6938
- };
6939
- LOD_METRIC_TYPE = {
6940
- GEOMETRIC_ERROR: "geometricError",
6941
- MAX_SCREEN_THRESHOLD: "maxScreenThreshold"
6942
- };
6925
+ (function(TILE_REFINEMENT2) {
6926
+ TILE_REFINEMENT2[TILE_REFINEMENT2["ADD"] = 1] = "ADD";
6927
+ TILE_REFINEMENT2[TILE_REFINEMENT2["REPLACE"] = 2] = "REPLACE";
6928
+ })(TILE_REFINEMENT || (TILE_REFINEMENT = {}));
6929
+ (function(TILE_TYPE2) {
6930
+ TILE_TYPE2["EMPTY"] = "empty";
6931
+ TILE_TYPE2["SCENEGRAPH"] = "scenegraph";
6932
+ TILE_TYPE2["POINTCLOUD"] = "pointcloud";
6933
+ TILE_TYPE2["MESH"] = "mesh";
6934
+ })(TILE_TYPE || (TILE_TYPE = {}));
6935
+ (function(TILESET_TYPE2) {
6936
+ TILESET_TYPE2["I3S"] = "I3S";
6937
+ TILESET_TYPE2["TILES3D"] = "TILES3D";
6938
+ })(TILESET_TYPE || (TILESET_TYPE = {}));
6939
+ (function(LOD_METRIC_TYPE2) {
6940
+ LOD_METRIC_TYPE2["GEOMETRIC_ERROR"] = "geometricError";
6941
+ LOD_METRIC_TYPE2["MAX_SCREEN_THRESHOLD"] = "maxScreenThreshold";
6942
+ })(LOD_METRIC_TYPE || (LOD_METRIC_TYPE = {}));
6943
6943
  }
6944
6944
  });
6945
6945
 
@@ -8453,26 +8453,26 @@
8453
8453
  return byteOffset;
8454
8454
  }
8455
8455
  function parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options) {
8456
- const { featureTableJsonByteLength, featureTableBinaryByteLength, batchLength } = tile.header;
8456
+ const { featureTableJsonByteLength, featureTableBinaryByteLength, batchLength } = tile.header || {};
8457
8457
  tile.featureTableJson = {
8458
8458
  BATCH_LENGTH: batchLength || 0
8459
8459
  };
8460
- if (featureTableJsonByteLength > 0) {
8460
+ if (featureTableJsonByteLength && featureTableJsonByteLength > 0) {
8461
8461
  const featureTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, featureTableJsonByteLength);
8462
8462
  tile.featureTableJson = JSON.parse(featureTableString);
8463
8463
  }
8464
- byteOffset += featureTableJsonByteLength;
8464
+ byteOffset += featureTableJsonByteLength || 0;
8465
8465
  tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
8466
- byteOffset += featureTableBinaryByteLength;
8466
+ byteOffset += featureTableBinaryByteLength || 0;
8467
8467
  return byteOffset;
8468
8468
  }
8469
8469
  function parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options) {
8470
- const { batchTableJsonByteLength, batchTableBinaryByteLength } = tile.header;
8471
- if (batchTableJsonByteLength > 0) {
8470
+ const { batchTableJsonByteLength, batchTableBinaryByteLength } = tile.header || {};
8471
+ if (batchTableJsonByteLength && batchTableJsonByteLength > 0) {
8472
8472
  const batchTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, batchTableJsonByteLength);
8473
8473
  tile.batchTableJson = JSON.parse(batchTableString);
8474
8474
  byteOffset += batchTableJsonByteLength;
8475
- if (batchTableBinaryByteLength > 0) {
8475
+ if (batchTableBinaryByteLength && batchTableBinaryByteLength > 0) {
8476
8476
  tile.batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
8477
8477
  tile.batchTableBinary = new Uint8Array(tile.batchTableBinary);
8478
8478
  byteOffset += batchTableBinaryByteLength;
@@ -8494,7 +8494,7 @@
8494
8494
  if (!colors && (!tile || !tile.batchIds || !batchTable)) {
8495
8495
  return null;
8496
8496
  }
8497
- const { batchIds, isRGB565, pointCount } = tile;
8497
+ const { batchIds, isRGB565, pointCount = 0 } = tile;
8498
8498
  if (batchIds && batchTable) {
8499
8499
  const colorArray = new Uint8ClampedArray(pointCount * 3);
8500
8500
  for (let i2 = 0; i2 < pointCount; i2++) {
@@ -8512,7 +8512,7 @@
8512
8512
  normalized: true
8513
8513
  };
8514
8514
  }
8515
- if (isRGB565) {
8515
+ if (colors && isRGB565) {
8516
8516
  const colorArray = new Uint8ClampedArray(pointCount * 3);
8517
8517
  for (let i2 = 0; i2 < pointCount; i2++) {
8518
8518
  const color = decodeRGB565(colors[i2]);
@@ -8537,7 +8537,7 @@
8537
8537
  }
8538
8538
  return {
8539
8539
  type: GL2.UNSIGNED_BYTE,
8540
- value: colors,
8540
+ value: colors || new Uint8ClampedArray(),
8541
8541
  size: 4,
8542
8542
  normalized: true
8543
8543
  };
@@ -8554,8 +8554,8 @@
8554
8554
  return null;
8555
8555
  }
8556
8556
  if (tile.isOctEncoded16P) {
8557
- const decodedArray = new Float32Array(tile.pointsLength * 3);
8558
- for (let i2 = 0; i2 < tile.pointsLength; i2++) {
8557
+ const decodedArray = new Float32Array((tile.pointsLength || 0) * 3);
8558
+ for (let i2 = 0; i2 < (tile.pointsLength || 0); i2++) {
8559
8559
  octDecode(normals[i2 * 2], normals[i2 * 2 + 1], scratchNormal4);
8560
8560
  scratchNormal4.toArray(decodedArray, i2 * 3);
8561
8561
  }
@@ -8651,6 +8651,12 @@
8651
8651
  return { featureTable, batchTable };
8652
8652
  }
8653
8653
  function parsePositions(tile, featureTable, options) {
8654
+ tile.attributes = tile.attributes || {
8655
+ positions: null,
8656
+ colors: null,
8657
+ normals: null,
8658
+ batchIds: null
8659
+ };
8654
8660
  if (!tile.attributes.positions) {
8655
8661
  if (featureTable.hasProperty("POSITION")) {
8656
8662
  tile.attributes.positions = featureTable.getPropertyArray("POSITION", GL2.FLOAT, 3);
@@ -8674,6 +8680,12 @@
8674
8680
  }
8675
8681
  }
8676
8682
  function parseColors(tile, featureTable, batchTable) {
8683
+ tile.attributes = tile.attributes || {
8684
+ positions: null,
8685
+ colors: null,
8686
+ normals: null,
8687
+ batchIds: null
8688
+ };
8677
8689
  if (!tile.attributes.colors) {
8678
8690
  let colors = null;
8679
8691
  if (featureTable.hasProperty("RGBA")) {
@@ -8692,6 +8704,12 @@
8692
8704
  }
8693
8705
  }
8694
8706
  function parseNormals(tile, featureTable) {
8707
+ tile.attributes = tile.attributes || {
8708
+ positions: null,
8709
+ colors: null,
8710
+ normals: null,
8711
+ batchIds: null
8712
+ };
8695
8713
  if (!tile.attributes.normals) {
8696
8714
  let normals = null;
8697
8715
  if (featureTable.hasProperty("NORMAL")) {
@@ -8734,7 +8752,7 @@
8734
8752
  if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
8735
8753
  throw new Error("Draco properties, byteOffset, and byteLength must be defined");
8736
8754
  }
8737
- dracoBuffer = tile.featureTableBinary.slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
8755
+ dracoBuffer = (tile.featureTableBinary || []).slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
8738
8756
  tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
8739
8757
  tile.hasColors = Number.isFinite(dracoFeatureTableProperties.RGB) || Number.isFinite(dracoFeatureTableProperties.RGBA);
8740
8758
  tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
@@ -8754,11 +8772,14 @@
8754
8772
  return await loadDraco(tile, dracoData, options, context);
8755
8773
  }
8756
8774
  async function loadDraco(tile, dracoData, options, context) {
8775
+ if (!context) {
8776
+ return;
8777
+ }
8757
8778
  const { parse: parse5 } = context;
8758
8779
  const dracoOptions = {
8759
8780
  ...options,
8760
8781
  draco: {
8761
- ...options.draco,
8782
+ ...options?.draco,
8762
8783
  extraAttributes: dracoData.batchTableProperties || {}
8763
8784
  }
8764
8785
  };
@@ -9328,6 +9349,7 @@
9328
9349
  "../images/src/index.ts"() {
9329
9350
  init_image_loader();
9330
9351
  init_binary_image_api();
9352
+ init_parsed_image_api();
9331
9353
  init_image_format();
9332
9354
  }
9333
9355
  });
@@ -10061,7 +10083,8 @@
10061
10083
  constructor(gltf) {
10062
10084
  this.gltf = {
10063
10085
  json: gltf?.json || makeDefaultGLTFJson(),
10064
- buffers: gltf?.buffers || []
10086
+ buffers: gltf?.buffers || [],
10087
+ images: gltf?.images || []
10065
10088
  };
10066
10089
  this.sourceBuffers = [];
10067
10090
  this.byteLength = 0;
@@ -10317,14 +10340,14 @@
10317
10340
  this.json.images.push(glTFImage);
10318
10341
  return this.json.images.length - 1;
10319
10342
  }
10320
- addBufferView(buffer) {
10343
+ addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) {
10321
10344
  const byteLength = buffer.byteLength;
10322
10345
  assert7(Number.isFinite(byteLength));
10323
10346
  this.sourceBuffers = this.sourceBuffers || [];
10324
10347
  this.sourceBuffers.push(buffer);
10325
10348
  const glTFBufferView = {
10326
- buffer: 0,
10327
- byteOffset: this.byteLength,
10349
+ buffer: bufferIndex,
10350
+ byteOffset,
10328
10351
  byteLength
10329
10352
  };
10330
10353
  this.byteLength += padToNBytes(byteLength, 4);
@@ -11280,18 +11303,16 @@
11280
11303
  decode: () => decode8,
11281
11304
  name: () => name9
11282
11305
  });
11283
- async function decode8(gltfData) {
11306
+ async function decode8(gltfData, options) {
11284
11307
  const scenegraph = new GLTFScenegraph(gltfData);
11285
- decodeExtFeatureMetadata(scenegraph);
11308
+ decodeExtFeatureMetadata(scenegraph, options);
11286
11309
  }
11287
- function decodeExtFeatureMetadata(scenegraph) {
11310
+ function decodeExtFeatureMetadata(scenegraph, options) {
11288
11311
  const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
11289
- const schemaClasses = extension?.schema?.classes;
11290
- const featureTables = extension?.featureTables;
11291
- const featureTextures = extension?.featureTextures;
11292
- if (featureTextures) {
11293
- console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
11294
- }
11312
+ if (!extension)
11313
+ return;
11314
+ const schemaClasses = extension.schema?.classes;
11315
+ const { featureTables } = extension;
11295
11316
  if (schemaClasses && featureTables) {
11296
11317
  for (const schemaName in schemaClasses) {
11297
11318
  const schemaClass = schemaClasses[schemaName];
@@ -11301,6 +11322,16 @@
11301
11322
  }
11302
11323
  }
11303
11324
  }
11325
+ const { featureTextures } = extension;
11326
+ if (schemaClasses && featureTextures && options.gltf?.loadImages) {
11327
+ for (const schemaName in schemaClasses) {
11328
+ const schemaClass = schemaClasses[schemaName];
11329
+ const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
11330
+ if (featureTexture) {
11331
+ handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
11332
+ }
11333
+ }
11334
+ }
11304
11335
  }
11305
11336
  function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
11306
11337
  for (const propertyName in schemaClass.properties) {
@@ -11313,19 +11344,128 @@
11313
11344
  }
11314
11345
  }
11315
11346
  }
11347
+ function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
11348
+ const attributeName = featureTexture.class;
11349
+ for (const propertyName in schemaClass.properties) {
11350
+ const featureTextureProperty = featureTexture?.properties?.[propertyName];
11351
+ if (featureTextureProperty) {
11352
+ const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
11353
+ featureTextureProperty.data = data;
11354
+ }
11355
+ }
11356
+ }
11316
11357
  function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
11317
11358
  const bufferView = featureTableProperty.bufferView;
11318
- let data = scenegraph.getTypedArrayForBufferView(bufferView);
11359
+ const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
11319
11360
  switch (schemaProperty.type) {
11320
11361
  case "STRING": {
11321
11362
  const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
11322
11363
  const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
11323
- data = getStringAttributes(data, offsetsData, numberOfFeatures);
11324
- break;
11364
+ return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
11325
11365
  }
11326
11366
  default:
11327
11367
  }
11328
- return data;
11368
+ return dataArray;
11369
+ }
11370
+ function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
11371
+ const json = scenegraph.gltf.json;
11372
+ if (!json.meshes) {
11373
+ return [];
11374
+ }
11375
+ const featureTextureTable = [];
11376
+ for (const mesh of json.meshes) {
11377
+ for (const primitive of mesh.primitives) {
11378
+ processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
11379
+ }
11380
+ }
11381
+ return featureTextureTable;
11382
+ }
11383
+ function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
11384
+ const json = scenegraph.gltf.json;
11385
+ const textureData = [];
11386
+ const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
11387
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
11388
+ const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
11389
+ const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
11390
+ const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
11391
+ const textureIndex = featureTextureProperty.texture.index;
11392
+ const texture = json.textures?.[textureIndex];
11393
+ const imageIndex = texture?.source;
11394
+ if (typeof imageIndex !== "undefined") {
11395
+ const image = json.images?.[imageIndex];
11396
+ const mimeType = image?.mimeType;
11397
+ const parsedImage = scenegraph.gltf.images?.[imageIndex];
11398
+ if (parsedImage) {
11399
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
11400
+ const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, featureTextureProperty.channels);
11401
+ textureData.push(value);
11402
+ }
11403
+ }
11404
+ }
11405
+ const featureIndices = [];
11406
+ for (const texelData of textureData) {
11407
+ let index = featureTextureTable.findIndex((item) => item === texelData);
11408
+ if (index === -1) {
11409
+ index = featureTextureTable.push(texelData) - 1;
11410
+ }
11411
+ featureIndices.push(index);
11412
+ }
11413
+ const typedArray = new Uint32Array(featureIndices);
11414
+ const bufferIndex = scenegraph.gltf.buffers.push({
11415
+ arrayBuffer: typedArray.buffer,
11416
+ byteOffset: 0,
11417
+ byteLength: typedArray.byteLength
11418
+ }) - 1;
11419
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
11420
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
11421
+ size: 1,
11422
+ componentType: getComponentTypeFromArray(typedArray),
11423
+ count: typedArray.length
11424
+ });
11425
+ primitive.attributes[attributeName] = accessorIndex;
11426
+ }
11427
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels) {
11428
+ const CHANNELS_MAP = {
11429
+ r: { offset: 0, shift: 0 },
11430
+ g: { offset: 1, shift: 8 },
11431
+ b: { offset: 2, shift: 16 },
11432
+ a: { offset: 3, shift: 24 }
11433
+ };
11434
+ const u = textureCoordinates[index];
11435
+ const v = textureCoordinates[index + 1];
11436
+ let components = 1;
11437
+ if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1))
11438
+ components = 4;
11439
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
11440
+ let value = 0;
11441
+ for (const c of channels) {
11442
+ const map2 = CHANNELS_MAP[c];
11443
+ const val = getVal(parsedImage, offset + map2.offset);
11444
+ value |= val << map2.shift;
11445
+ }
11446
+ return value;
11447
+ }
11448
+ function getVal(parsedImage, offset) {
11449
+ const imageData = getImageData(parsedImage);
11450
+ if (imageData.data.length <= offset) {
11451
+ throw new Error(`${imageData.data.length} <= ${offset}`);
11452
+ }
11453
+ return imageData.data[offset];
11454
+ }
11455
+ function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
11456
+ const w = parsedImage.width;
11457
+ const iX = emod(u) * (w - 1);
11458
+ const indX = Math.round(iX);
11459
+ const h = parsedImage.height;
11460
+ const iY = emod(v) * (h - 1);
11461
+ const indY = Math.round(iY);
11462
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
11463
+ const offset = (indY * w + indX) * components;
11464
+ return offset;
11465
+ }
11466
+ function emod(n2) {
11467
+ const a2 = (n2 % 1 + 1) % 1;
11468
+ return a2;
11329
11469
  }
11330
11470
  function findFeatureTableByName(featureTables, schemaClassName) {
11331
11471
  for (const featureTableName in featureTables) {
@@ -11336,6 +11476,15 @@
11336
11476
  }
11337
11477
  return null;
11338
11478
  }
11479
+ function findFeatureTextureByName(featureTextures, schemaClassName) {
11480
+ for (const featureTexturesName in featureTextures) {
11481
+ const featureTable = featureTextures[featureTexturesName];
11482
+ if (featureTable.class === schemaClassName) {
11483
+ return featureTable;
11484
+ }
11485
+ }
11486
+ return null;
11487
+ }
11339
11488
  function getStringAttributes(data, offsetsData, stringsCount) {
11340
11489
  const stringsArray = [];
11341
11490
  const textDecoder = new TextDecoder("utf8");
@@ -11354,6 +11503,8 @@
11354
11503
  var init_EXT_feature_metadata = __esm({
11355
11504
  "../gltf/src/lib/extensions/deprecated/EXT_feature_metadata.ts"() {
11356
11505
  init_gltf_scenegraph();
11506
+ init_src8();
11507
+ init_gltf_utils();
11357
11508
  EXT_FEATURE_METADATA = "EXT_feature_metadata";
11358
11509
  name9 = EXT_FEATURE_METADATA;
11359
11510
  }
@@ -11632,17 +11783,13 @@
11632
11783
  parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
11633
11784
  normalizeGLTFV1(gltf, { normalize: options?.gltf?.normalize });
11634
11785
  preprocessExtensions(gltf, options, context);
11635
- const promises = [];
11636
11786
  if (options?.gltf?.loadBuffers && gltf.json.buffers) {
11637
11787
  await loadBuffers(gltf, options, context);
11638
11788
  }
11639
11789
  if (options?.gltf?.loadImages) {
11640
- const promise2 = loadImages(gltf, options, context);
11641
- promises.push(promise2);
11790
+ await loadImages(gltf, options, context);
11642
11791
  }
11643
- const promise = decodeExtensions(gltf, options, context);
11644
- promises.push(promise);
11645
- await Promise.all(promises);
11792
+ await decodeExtensions(gltf, options, context);
11646
11793
  return gltf;
11647
11794
  }
11648
11795
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
@@ -12197,11 +12344,11 @@
12197
12344
  // src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts
12198
12345
  function parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options) {
12199
12346
  tile.rotateYtoZ = true;
12200
- const gltfByteLength = tile.byteOffset + tile.byteLength - byteOffset;
12347
+ const gltfByteLength = (tile.byteOffset || 0) + (tile.byteLength || 0) - byteOffset;
12201
12348
  if (gltfByteLength === 0) {
12202
12349
  throw new Error("glTF byte length must be greater than 0.");
12203
12350
  }
12204
- tile.gltfUpAxis = options["3d-tiles"] && options["3d-tiles"].assetGltfUpAxis ? options["3d-tiles"].assetGltfUpAxis : "Y";
12351
+ tile.gltfUpAxis = options?.["3d-tiles"] && options["3d-tiles"].assetGltfUpAxis ? options["3d-tiles"].assetGltfUpAxis : "Y";
12205
12352
  tile.gltfArrayBuffer = sliceArrayBuffer(arrayBuffer, byteOffset, gltfByteLength);
12206
12353
  tile.gltfByteOffset = 0;
12207
12354
  tile.gltfByteLength = gltfByteLength;
@@ -12209,15 +12356,19 @@
12209
12356
  } else {
12210
12357
  console.warn(`${tile.type}: embedded glb is not aligned to a 4-byte boundary.`);
12211
12358
  }
12212
- return tile.byteOffset + tile.byteLength;
12359
+ return (tile.byteOffset || 0) + (tile.byteLength || 0);
12213
12360
  }
12214
12361
  async function extractGLTF(tile, gltfFormat, options, context) {
12215
- const tile3DOptions = options["3d-tiles"] || {};
12362
+ const tile3DOptions = options?.["3d-tiles"] || {};
12216
12363
  extractGLTFBufferOrURL(tile, gltfFormat, options);
12217
12364
  if (tile3DOptions.loadGLTF) {
12365
+ if (!context) {
12366
+ return;
12367
+ }
12218
12368
  const { parse: parse5, fetch: fetch2 } = context;
12219
12369
  if (tile.gltfUrl) {
12220
- tile.gltfArrayBuffer = await fetch2(tile.gltfUrl, options);
12370
+ const response = await fetch2(tile.gltfUrl, options);
12371
+ tile.gltfArrayBuffer = await response.arrayBuffer();
12221
12372
  tile.gltfByteOffset = 0;
12222
12373
  }
12223
12374
  if (tile.gltfArrayBuffer) {
@@ -12233,10 +12384,12 @@
12233
12384
  function extractGLTFBufferOrURL(tile, gltfFormat, options) {
12234
12385
  switch (gltfFormat) {
12235
12386
  case GLTF_FORMAT.URI:
12236
- const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
12237
- const textDecoder = new TextDecoder();
12238
- const gltfUrl = textDecoder.decode(gltfUrlBytes);
12239
- tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, "");
12387
+ if (tile.gltfArrayBuffer) {
12388
+ const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
12389
+ const textDecoder = new TextDecoder();
12390
+ const gltfUrl = textDecoder.decode(gltfUrlBytes);
12391
+ tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, "");
12392
+ }
12240
12393
  delete tile.gltfArrayBuffer;
12241
12394
  delete tile.gltfByteOffset;
12242
12395
  delete tile.gltfByteLength;
@@ -12291,7 +12444,7 @@
12291
12444
  // src/lib/parsers/parse-3d-tile-instanced-model.ts
12292
12445
  async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
12293
12446
  byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
12294
- await extractGLTF(tile, tile.gltfFormat, options, context);
12447
+ await extractGLTF(tile, tile.gltfFormat || 0, options, context);
12295
12448
  return byteOffset;
12296
12449
  }
12297
12450
  function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
@@ -12305,7 +12458,7 @@
12305
12458
  byteOffset += 4;
12306
12459
  byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
12307
12460
  byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
12308
- if (tile.featureTableJsonByteLength === 0) {
12461
+ if (!tile?.header?.featureTableJsonByteLength || tile.header.featureTableJsonByteLength === 0) {
12309
12462
  throw new Error("i3dm parser: featureTableJsonByteLength is zero.");
12310
12463
  }
12311
12464
  const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
@@ -12321,17 +12474,7 @@
12321
12474
  return byteOffset;
12322
12475
  }
12323
12476
  function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
12324
- const collectionOptions = {
12325
- instances: new Array(instancesLength),
12326
- batchTable: tile._batchTable,
12327
- cull: false,
12328
- url: void 0,
12329
- gltf: void 0,
12330
- basePath: void 0,
12331
- incrementallyLoadTextures: false,
12332
- forwardAxis: [1, 0, 0]
12333
- };
12334
- const instances = collectionOptions.instances;
12477
+ const instances = new Array(instancesLength);
12335
12478
  const instancePosition = new Vector3();
12336
12479
  const instanceNormalRight = new Vector3();
12337
12480
  const instanceNormalUp = new Vector3();
@@ -12343,19 +12486,19 @@
12343
12486
  const instanceTransform = new Matrix4();
12344
12487
  const scratch1 = [];
12345
12488
  const scratch2 = [];
12346
- const scratchVector12 = new Vector3();
12347
- const scratchVector26 = new Vector3();
12489
+ const scratch3 = [];
12490
+ const scratch4 = [];
12348
12491
  for (let i2 = 0; i2 < instancesLength; i2++) {
12349
12492
  let position;
12350
12493
  if (featureTable.hasProperty("POSITION")) {
12351
12494
  position = featureTable.getProperty("POSITION", GL2.FLOAT, 3, i2, instancePosition);
12352
12495
  } else if (featureTable.hasProperty("POSITION_QUANTIZED")) {
12353
12496
  position = featureTable.getProperty("POSITION_QUANTIZED", GL2.UNSIGNED_SHORT, 3, i2, instancePosition);
12354
- const quantizedVolumeOffset = featureTable.getGlobalProperty("QUANTIZED_VOLUME_OFFSET", GL2.FLOAT, 3, scratchVector12);
12497
+ const quantizedVolumeOffset = featureTable.getGlobalProperty("QUANTIZED_VOLUME_OFFSET", GL2.FLOAT, 3);
12355
12498
  if (!quantizedVolumeOffset) {
12356
12499
  throw new Error("i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.");
12357
12500
  }
12358
- const quantizedVolumeScale = featureTable.getGlobalProperty("QUANTIZED_VOLUME_SCALE", GL2.FLOAT, 3, scratchVector26);
12501
+ const quantizedVolumeScale = featureTable.getGlobalProperty("QUANTIZED_VOLUME_SCALE", GL2.FLOAT, 3);
12359
12502
  if (!quantizedVolumeScale) {
12360
12503
  throw new Error("i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.");
12361
12504
  }
@@ -12378,8 +12521,8 @@
12378
12521
  }
12379
12522
  tile.hasCustomOrientation = true;
12380
12523
  } else {
12381
- tile.octNormalUp = featureTable.getProperty("NORMAL_UP_OCT32P", GL2.UNSIGNED_SHORT, 2, scratch1);
12382
- tile.octNormalRight = featureTable.getProperty("NORMAL_RIGHT_OCT32P", GL2.UNSIGNED_SHORT, 2, scratch2);
12524
+ tile.octNormalUp = featureTable.getProperty("NORMAL_UP_OCT32P", GL2.UNSIGNED_SHORT, 2, i2, scratch1);
12525
+ tile.octNormalRight = featureTable.getProperty("NORMAL_RIGHT_OCT32P", GL2.UNSIGNED_SHORT, 2, i2, scratch2);
12383
12526
  if (tile.octNormalUp) {
12384
12527
  if (!tile.octNormalRight) {
12385
12528
  throw new Error("i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P");
@@ -12401,7 +12544,7 @@
12401
12544
  instanceQuaternion.fromMatrix3(instanceRotation);
12402
12545
  instanceTranslationRotationScale.rotation = instanceQuaternion;
12403
12546
  instanceScale.set(1, 1, 1);
12404
- const scale5 = featureTable.getProperty("SCALE", GL2.FLOAT, 1, i2);
12547
+ const scale5 = featureTable.getProperty("SCALE", GL2.FLOAT, 1, i2, scratch3);
12405
12548
  if (Number.isFinite(scale5)) {
12406
12549
  instanceScale.multiplyByScalar(scale5);
12407
12550
  }
@@ -12410,7 +12553,7 @@
12410
12553
  instanceScale.scale(nonUniformScale);
12411
12554
  }
12412
12555
  instanceTranslationRotationScale.scale = instanceScale;
12413
- let batchId = featureTable.getProperty("BATCH_ID", GL2.UNSIGNED_SHORT, 1, i2);
12556
+ let batchId = featureTable.getProperty("BATCH_ID", GL2.UNSIGNED_SHORT, 1, i2, scratch4);
12414
12557
  if (batchId === void 0) {
12415
12558
  batchId = i2;
12416
12559
  }
@@ -12447,7 +12590,7 @@
12447
12590
  tile.tilesLength = view.getUint32(byteOffset, true);
12448
12591
  byteOffset += 4;
12449
12592
  tile.tiles = [];
12450
- while (tile.tiles.length < tile.tilesLength && tile.byteLength - byteOffset > 12) {
12593
+ while (tile.tiles.length < tile.tilesLength && (tile.byteLength || 0) - byteOffset > 12) {
12451
12594
  const subtile = {};
12452
12595
  tile.tiles.push(subtile);
12453
12596
  byteOffset = await parse3DTile2(arrayBuffer, byteOffset, options, context, subtile);
@@ -12463,11 +12606,18 @@
12463
12606
  // src/lib/parsers/parse-3d-tile-gltf.ts
12464
12607
  async function parseGltf3DTile(tile, arrayBuffer, options, context) {
12465
12608
  tile.rotateYtoZ = true;
12466
- tile.gltfUpAxis = options["3d-tiles"] && options["3d-tiles"].assetGltfUpAxis ? options["3d-tiles"].assetGltfUpAxis : "Y";
12467
- const { parse: parse5 } = context;
12468
- const gltfWithBuffers = await parse5(arrayBuffer, GLTFLoader, options, context);
12469
- tile.gltf = postProcessGLTF(gltfWithBuffers);
12470
- tile.gpuMemoryUsageInBytes = getMemoryUsageGLTF(tile.gltf);
12609
+ tile.gltfUpAxis = options?.["3d-tiles"] && options["3d-tiles"].assetGltfUpAxis ? options["3d-tiles"].assetGltfUpAxis : "Y";
12610
+ if (options?.["3d-tiles"]?.loadGLTF) {
12611
+ if (!context) {
12612
+ return;
12613
+ }
12614
+ const { parse: parse5 } = context;
12615
+ const gltfWithBuffers = await parse5(arrayBuffer, GLTFLoader, options, context);
12616
+ tile.gltf = postProcessGLTF(gltfWithBuffers);
12617
+ tile.gpuMemoryUsageInBytes = getMemoryUsageGLTF(tile.gltf);
12618
+ } else {
12619
+ tile.gltfArrayBuffer = arrayBuffer;
12620
+ }
12471
12621
  }
12472
12622
  var init_parse_3d_tile_gltf = __esm({
12473
12623
  "src/lib/parsers/parse-3d-tile-gltf.ts"() {
@@ -14044,11 +14194,11 @@
14044
14194
  });
14045
14195
 
14046
14196
  // src/lib/parsers/parse-3d-tile-header.ts
14047
- function getTileType(tile) {
14048
- if (!tile.contentUrl) {
14197
+ function getTileType(tile, tileContentUrl = "") {
14198
+ if (!tileContentUrl) {
14049
14199
  return TILE_TYPE.EMPTY;
14050
14200
  }
14051
- const contentUrl = tile.contentUrl.split("?")[0];
14201
+ const contentUrl = tileContentUrl.split("?")[0];
14052
14202
  const fileExtension = contentUrl.split(".").pop();
14053
14203
  switch (fileExtension) {
14054
14204
  case "pnts":
@@ -14059,7 +14209,7 @@
14059
14209
  case "gltf":
14060
14210
  return TILE_TYPE.SCENEGRAPH;
14061
14211
  default:
14062
- return fileExtension;
14212
+ return fileExtension || TILE_TYPE.EMPTY;
14063
14213
  }
14064
14214
  }
14065
14215
  function getRefine(refine) {
@@ -14074,7 +14224,7 @@
14074
14224
  return refine;
14075
14225
  }
14076
14226
  }
14077
- function resolveUri(uri, basePath) {
14227
+ function resolveUri(uri = "", basePath) {
14078
14228
  const urlSchemeRegex = /^[a-z][0-9a-z+.-]*:/i;
14079
14229
  if (urlSchemeRegex.test(basePath)) {
14080
14230
  const url = new URL(uri, `${basePath}/`);
@@ -14084,50 +14234,59 @@
14084
14234
  }
14085
14235
  return `${basePath}/${uri}`;
14086
14236
  }
14087
- function normalizeTileData(tile, options) {
14237
+ function normalizeTileData(tile, basePath) {
14088
14238
  if (!tile) {
14089
14239
  return null;
14090
14240
  }
14241
+ let tileContentUrl;
14091
14242
  if (tile.content) {
14092
- const contentUri = tile.content.uri || tile.content.url;
14093
- tile.contentUrl = resolveUri(contentUri, options.basePath);
14094
- }
14095
- tile.id = tile.contentUrl;
14096
- tile.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
14097
- tile.lodMetricValue = tile.geometricError;
14098
- tile.transformMatrix = tile.transform;
14099
- tile.type = getTileType(tile);
14100
- tile.refine = getRefine(tile.refine);
14101
- return tile;
14243
+ const contentUri = tile.content.uri || tile.content?.url;
14244
+ tileContentUrl = resolveUri(contentUri, basePath);
14245
+ }
14246
+ const tilePostprocessed = {
14247
+ ...tile,
14248
+ id: tileContentUrl,
14249
+ contentUrl: tileContentUrl,
14250
+ lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
14251
+ lodMetricValue: tile.geometricError,
14252
+ transformMatrix: tile.transform,
14253
+ type: getTileType(tile, tileContentUrl),
14254
+ refine: getRefine(tile.refine)
14255
+ };
14256
+ return tilePostprocessed;
14102
14257
  }
14103
- async function normalizeTileHeaders(tileset, options) {
14104
- const basePath = tileset.basePath;
14105
- let root;
14106
- const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset?.root);
14258
+ async function normalizeTileHeaders(tileset, basePath, options) {
14259
+ let root = null;
14260
+ const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset.root);
14107
14261
  if (rootImplicitTilingExtension && tileset.root) {
14108
- root = await normalizeImplicitTileHeaders(tileset.root, tileset, rootImplicitTilingExtension, options);
14262
+ root = await normalizeImplicitTileHeaders(tileset.root, tileset, basePath, rootImplicitTilingExtension, options);
14109
14263
  } else {
14110
- root = normalizeTileData(tileset.root, tileset);
14264
+ root = normalizeTileData(tileset.root, basePath);
14111
14265
  }
14112
14266
  const stack2 = [];
14113
14267
  stack2.push(root);
14114
14268
  while (stack2.length > 0) {
14115
14269
  const tile = stack2.pop() || {};
14116
14270
  const children = tile.children || [];
14117
- for (let childHeader of children) {
14271
+ const childrenPostprocessed = [];
14272
+ for (const childHeader of children) {
14118
14273
  const childImplicitTilingExtension = getImplicitTilingExtensionData(childHeader);
14274
+ let childHeaderPostprocessed;
14119
14275
  if (childImplicitTilingExtension) {
14120
- childHeader = await normalizeImplicitTileHeaders(childHeader, tileset, childImplicitTilingExtension, options);
14276
+ childHeaderPostprocessed = await normalizeImplicitTileHeaders(childHeader, tileset, basePath, childImplicitTilingExtension, options);
14121
14277
  } else {
14122
- normalizeTileData(childHeader, { basePath });
14278
+ childHeaderPostprocessed = normalizeTileData(childHeader, basePath);
14279
+ }
14280
+ if (childHeaderPostprocessed) {
14281
+ childrenPostprocessed.push(childHeaderPostprocessed);
14282
+ stack2.push(childHeaderPostprocessed);
14123
14283
  }
14124
- stack2.push(childHeader);
14125
14284
  }
14285
+ tile.children = childrenPostprocessed;
14126
14286
  }
14127
14287
  return root;
14128
14288
  }
14129
- async function normalizeImplicitTileHeaders(tile, tileset, implicitTilingExtension, options) {
14130
- const basePath = tileset.basePath;
14289
+ async function normalizeImplicitTileHeaders(tile, tileset, basePath, implicitTilingExtension, options) {
14131
14290
  const {
14132
14291
  subdivisionScheme,
14133
14292
  maximumLevel,
@@ -14137,7 +14296,7 @@
14137
14296
  const replacedUrlTemplate = replaceContentUrlTemplate(subtreesUriTemplate, 0, 0, 0, 0);
14138
14297
  const subtreeUrl = resolveUri(replacedUrlTemplate, basePath);
14139
14298
  const subtree = await load(subtreeUrl, Tile3DSubtreeLoader, options);
14140
- const contentUrlTemplate = resolveUri(tile.content.uri, basePath);
14299
+ const contentUrlTemplate = resolveUri(tile.content?.uri, basePath);
14141
14300
  const refine = tileset?.root?.refine;
14142
14301
  const rootLodMetricValue = tile.geometricError;
14143
14302
  const s2VolumeInfo = tile.boundingVolume.extensions?.["3DTILES_bounding_volume_S2"];
@@ -14161,29 +14320,35 @@
14161
14320
  getTileType,
14162
14321
  getRefine
14163
14322
  };
14164
- return await normalizeImplicitTileData(tile, subtree, implicitOptions);
14323
+ return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions);
14165
14324
  }
14166
- async function normalizeImplicitTileData(tile, rootSubtree, options) {
14325
+ async function normalizeImplicitTileData(tile, basePath, rootSubtree, options) {
14167
14326
  if (!tile) {
14168
14327
  return null;
14169
14328
  }
14170
- tile.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
14171
- tile.lodMetricValue = tile.geometricError;
14172
- tile.transformMatrix = tile.transform;
14173
14329
  const { children, contentUrl } = await parseImplicitTiles({
14174
14330
  subtree: rootSubtree,
14175
- options,
14176
- s2VolumeBox: tile
14331
+ options
14177
14332
  });
14333
+ let tileContentUrl;
14334
+ let tileContent = null;
14178
14335
  if (contentUrl) {
14179
- tile.contentUrl = contentUrl;
14180
- tile.content = { uri: contentUrl.replace(`${options.basePath}/`, "") };
14336
+ tileContentUrl = contentUrl;
14337
+ tileContent = { uri: contentUrl.replace(`${basePath}/`, "") };
14181
14338
  }
14182
- tile.refine = getRefine(tile.refine);
14183
- tile.type = getTileType(tile);
14184
- tile.children = children;
14185
- tile.id = tile.contentUrl;
14186
- return tile;
14339
+ const tilePostprocessed = {
14340
+ ...tile,
14341
+ id: tileContentUrl,
14342
+ contentUrl: tileContentUrl,
14343
+ lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
14344
+ lodMetricValue: tile.geometricError,
14345
+ transformMatrix: tile.transform,
14346
+ type: getTileType(tile, tileContentUrl),
14347
+ refine: getRefine(tile.refine),
14348
+ content: tileContent || tile.content,
14349
+ children
14350
+ };
14351
+ return tilePostprocessed;
14187
14352
  }
14188
14353
  function getImplicitTilingExtensionData(tile) {
14189
14354
  return tile?.extensions?.["3DTILES_implicit_tiling"] || tile?.implicitTiling;
@@ -14207,19 +14372,25 @@
14207
14372
  } else {
14208
14373
  isTileset = loaderOptions.isTileset;
14209
14374
  }
14210
- return await isTileset ? parseTileset(data, options, context) : parseTile(data, options, context);
14375
+ return isTileset ? parseTileset(data, options, context) : parseTile(data, options, context);
14211
14376
  }
14212
14377
  async function parseTileset(data, options, context) {
14213
14378
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
14214
- tilesetJson.loader = options?.loader || Tiles3DLoader;
14215
- tilesetJson.url = context?.url || "";
14216
- tilesetJson.queryString = context?.queryString || "";
14217
- tilesetJson.basePath = getBaseUri(tilesetJson);
14218
- tilesetJson.root = await normalizeTileHeaders(tilesetJson, options || {});
14219
- tilesetJson.type = TILESET_TYPE.TILES3D;
14220
- tilesetJson.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
14221
- tilesetJson.lodMetricValue = tilesetJson.root?.lodMetricValue || 0;
14222
- return tilesetJson;
14379
+ const tilesetUrl = context?.url || "";
14380
+ const basePath = getBaseUri(tilesetUrl);
14381
+ const normalizedRoot = await normalizeTileHeaders(tilesetJson, basePath, options || {});
14382
+ const tilesetJsonPostprocessed = {
14383
+ ...tilesetJson,
14384
+ loader: Tiles3DLoader,
14385
+ url: tilesetUrl,
14386
+ queryString: context?.queryString || "",
14387
+ basePath,
14388
+ root: normalizedRoot || tilesetJson.root,
14389
+ type: TILESET_TYPE.TILES3D,
14390
+ lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
14391
+ lodMetricValue: tilesetJson.root?.geometricError || 0
14392
+ };
14393
+ return tilesetJsonPostprocessed;
14223
14394
  }
14224
14395
  async function parseTile(arrayBuffer, options, context) {
14225
14396
  const tile = {
@@ -14231,8 +14402,8 @@
14231
14402
  await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
14232
14403
  return tile.content;
14233
14404
  }
14234
- function getBaseUri(tileset) {
14235
- return path_exports.dirname(tileset.url);
14405
+ function getBaseUri(tilesetUrl) {
14406
+ return path_exports.dirname(tilesetUrl);
14236
14407
  }
14237
14408
  var Tiles3DLoader;
14238
14409
  var init_tiles_3d_loader = __esm({