@loaders.gl/gltf 4.0.0-alpha.24 → 4.0.0-alpha.26

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/dist.min.js +237 -146
  2. package/dist/es5/index.js +12 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/api/gltf-extensions.js +1 -1
  5. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  6. package/dist/es5/lib/extensions/EXT_mesh_features.js +12 -24
  7. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
  8. package/dist/es5/lib/extensions/EXT_structural_metadata.js +72 -28
  9. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
  10. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +38 -3
  11. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  12. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js +26 -18
  13. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
  14. package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
  15. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  16. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  17. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  18. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  19. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  20. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  21. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  22. package/dist/es5/lib/utils/version.js +1 -1
  23. package/dist/esm/index.js +2 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/lib/api/gltf-extensions.js +1 -1
  26. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  27. package/dist/esm/lib/extensions/EXT_mesh_features.js +13 -25
  28. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
  29. package/dist/esm/lib/extensions/EXT_structural_metadata.js +48 -14
  30. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
  31. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +38 -4
  32. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  33. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js +27 -19
  34. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -1
  35. package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
  36. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  37. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  38. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  39. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  40. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  41. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  42. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  43. package/dist/esm/lib/utils/version.js +1 -1
  44. package/dist/index.d.ts +6 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  47. package/dist/lib/extensions/EXT_structural_metadata.d.ts +9 -1
  48. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  49. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
  50. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  51. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +12 -12
  52. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  53. package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
  54. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  55. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
  56. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
  57. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +4 -6
  58. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  59. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +44 -25
  60. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  61. package/dist/lib/types/gltf-json-schema.d.ts +1 -420
  62. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  63. package/dist/lib/types/gltf-types.d.ts +3 -0
  64. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  65. package/package.json +6 -6
  66. package/src/index.ts +10 -5
  67. package/src/lib/api/gltf-extensions.ts +1 -1
  68. package/src/lib/extensions/EXT_mesh_features.ts +18 -44
  69. package/src/lib/extensions/EXT_structural_metadata.ts +176 -96
  70. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +70 -11
  71. package/src/lib/extensions/utils/3d-tiles-utils.ts +50 -39
  72. package/src/lib/gltf-utils/gltf-utils.ts +38 -0
  73. package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
  74. package/src/lib/types/gltf-ext-mesh-features-schema.ts +4 -6
  75. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +46 -27
  76. package/src/lib/types/gltf-json-schema.ts +1 -468
  77. package/src/lib/types/gltf-types.ts +4 -0
package/dist/dist.min.js CHANGED
@@ -78,15 +78,24 @@
78
78
  });
79
79
 
80
80
  // ../worker-utils/src/lib/env-utils/version.ts
81
- var DEFAULT_VERSION, VERSION2;
82
- var init_version2 = __esm({
83
- "../worker-utils/src/lib/env-utils/version.ts"() {
84
- DEFAULT_VERSION = "beta";
85
- VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : DEFAULT_VERSION;
81
+ function getVersion() {
82
+ if (!globalThis._loadersgl_?.version) {
83
+ globalThis._loadersgl_ = globalThis._loadersgl_ || {};
86
84
  if (typeof __VERSION__ === "undefined") {
87
85
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
86
+ globalThis._loadersgl_.version = NPM_TAG;
87
+ } else {
88
+ globalThis._loadersgl_.version = __VERSION__;
88
89
  }
89
90
  }
91
+ return globalThis._loadersgl_.version;
92
+ }
93
+ var NPM_TAG, VERSION2;
94
+ var init_version2 = __esm({
95
+ "../worker-utils/src/lib/env-utils/version.ts"() {
96
+ NPM_TAG = "beta";
97
+ VERSION2 = getVersion();
98
+ }
90
99
  });
91
100
 
92
101
  // ../worker-utils/src/lib/env-utils/assert.ts
@@ -150,7 +159,7 @@
150
159
  }
151
160
  if (options.CDN) {
152
161
  assert2(options.CDN.startsWith("http"));
153
- return `${options.CDN}/${moduleName}@${VERSION3}/dist/libs/${libraryName}`;
162
+ return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${libraryName}`;
154
163
  }
155
164
  if (isWorker) {
156
165
  return `../src/libs/${libraryName}`;
@@ -206,15 +215,13 @@
206
215
  }
207
216
  return await node.readFileAsText(url);
208
217
  }
209
- var node, LATEST, VERSION3, loadLibraryPromises;
218
+ var node, loadLibraryPromises;
210
219
  var init_library_utils = __esm({
211
220
  "../worker-utils/src/lib/library-utils/library-utils.ts"() {
212
221
  init_globals2();
213
222
  node = __toModule(require_require_utils());
214
223
  init_assert2();
215
224
  init_version2();
216
- LATEST = "beta";
217
- VERSION3 = typeof VERSION2 !== "undefined" ? VERSION2 : LATEST;
218
225
  loadLibraryPromises = {};
219
226
  }
220
227
  });
@@ -858,6 +865,30 @@
858
865
  }
859
866
  });
860
867
 
868
+ // src/lib/gltf-utils/gltf-constants.ts
869
+ var COMPONENTS, BYTES;
870
+ var init_gltf_constants = __esm({
871
+ "src/lib/gltf-utils/gltf-constants.ts"() {
872
+ COMPONENTS = {
873
+ SCALAR: 1,
874
+ VEC2: 2,
875
+ VEC3: 3,
876
+ VEC4: 4,
877
+ MAT2: 4,
878
+ MAT3: 9,
879
+ MAT4: 16
880
+ };
881
+ BYTES = {
882
+ 5120: 1,
883
+ 5121: 1,
884
+ 5122: 2,
885
+ 5123: 2,
886
+ 5125: 4,
887
+ 5126: 4
888
+ };
889
+ }
890
+ });
891
+
861
892
  // src/lib/gltf-utils/gltf-utils.ts
862
893
  function getAccessorTypeFromSize(size) {
863
894
  const type = TYPES[size - 1];
@@ -879,6 +910,27 @@
879
910
  assert3(byteLength >= 0 && byteLength <= bufferView.byteLength);
880
911
  return { ArrayType, length, byteLength };
881
912
  }
913
+ function getFloat32ArrayForAccessor(gltfData, texCoordAccessor) {
914
+ const accessor = gltfData.json.accessors?.[texCoordAccessor];
915
+ if (accessor && typeof accessor.bufferView !== "undefined") {
916
+ const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
917
+ if (bufferView) {
918
+ const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
919
+ const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
920
+ const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView);
921
+ const bytes = BYTES[accessor.componentType];
922
+ const components = COMPONENTS[accessor.type];
923
+ const elementAddressScale = bufferView.byteStride || bytes * components;
924
+ const result = new Float32Array(length);
925
+ for (let i2 = 0; i2 < accessor.count; i2++) {
926
+ const uv = new ArrayType(arrayBuffer, byteOffset + i2 * elementAddressScale, 2);
927
+ result.set(uv, i2 * components);
928
+ }
929
+ return result;
930
+ }
931
+ }
932
+ return null;
933
+ }
882
934
  function getMemoryUsageGLTF(gltf) {
883
935
  let { images, bufferViews } = gltf;
884
936
  images = images || [];
@@ -896,6 +948,7 @@
896
948
  var init_gltf_utils = __esm({
897
949
  "src/lib/gltf-utils/gltf-utils.ts"() {
898
950
  init_assert3();
951
+ init_gltf_constants();
899
952
  MIPMAP_FACTOR = 1.33;
900
953
  TYPES = ["SCALAR", "VEC2", "VEC3", "VEC4"];
901
954
  ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
@@ -2565,9 +2618,10 @@
2565
2618
  const json = scenegraph.gltf.json;
2566
2619
  const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
2567
2620
  const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
2568
- const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
2569
- const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
2570
- const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
2621
+ const textureCoordinates = getFloat32ArrayForAccessor(scenegraph.gltf, texCoordAccessorIndex);
2622
+ if (!textureCoordinates) {
2623
+ return null;
2624
+ }
2571
2625
  const textureIndex = textureInfo.index;
2572
2626
  const imageIndex = json.textures?.[textureIndex]?.source;
2573
2627
  if (typeof imageIndex !== "undefined") {
@@ -2585,8 +2639,9 @@
2585
2639
  return null;
2586
2640
  }
2587
2641
  function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
2588
- if (propertyData === null)
2642
+ if (!propertyData?.length) {
2589
2643
  return;
2644
+ }
2590
2645
  const featureIndices = [];
2591
2646
  for (const texelData of propertyData) {
2592
2647
  let index = featureTable.findIndex((item) => item === texelData);
@@ -2610,12 +2665,12 @@
2610
2665
  primitive.attributes[attributeName] = accessorIndex;
2611
2666
  }
2612
2667
  function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) {
2613
- const CHANNELS_MAP = [
2614
- { offset: 0, shift: 0 },
2615
- { offset: 1, shift: 8 },
2616
- { offset: 2, shift: 16 },
2617
- { offset: 3, shift: 24 }
2618
- ];
2668
+ const CHANNELS_MAP = {
2669
+ r: { offset: 0, shift: 0 },
2670
+ g: { offset: 1, shift: 8 },
2671
+ b: { offset: 2, shift: 16 },
2672
+ a: { offset: 3, shift: 24 }
2673
+ };
2619
2674
  const u = textureCoordinates[index];
2620
2675
  const v = textureCoordinates[index + 1];
2621
2676
  let components = 1;
@@ -2624,7 +2679,7 @@
2624
2679
  const offset = coordinatesToOffset(u, v, parsedImage, components);
2625
2680
  let value = 0;
2626
2681
  for (const c of channels) {
2627
- const map = CHANNELS_MAP[c];
2682
+ const map = typeof c === "number" ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c];
2628
2683
  const imageOffset = offset + map.offset;
2629
2684
  const imageData = getImageData(parsedImage);
2630
2685
  if (imageData.data.length <= imageOffset) {
@@ -2691,17 +2746,91 @@
2691
2746
  }
2692
2747
  });
2693
2748
 
2749
+ // src/lib/extensions/EXT_mesh_features.ts
2750
+ var EXT_mesh_features_exports = {};
2751
+ __export(EXT_mesh_features_exports, {
2752
+ decode: () => decode,
2753
+ name: () => name
2754
+ });
2755
+ async function decode(gltfData, options) {
2756
+ const scenegraph = new GLTFScenegraph(gltfData);
2757
+ decodeExtMeshFeatures(scenegraph, options);
2758
+ }
2759
+ function decodeExtMeshFeatures(scenegraph, options) {
2760
+ const json = scenegraph.gltf.json;
2761
+ if (!json.meshes) {
2762
+ return;
2763
+ }
2764
+ for (const mesh of json.meshes) {
2765
+ for (const primitive of mesh.primitives) {
2766
+ processMeshPrimitiveFeatures(scenegraph, primitive, options);
2767
+ }
2768
+ }
2769
+ }
2770
+ function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
2771
+ if (!options?.gltf?.loadBuffers) {
2772
+ return;
2773
+ }
2774
+ const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
2775
+ const featureIds = extension?.featureIds;
2776
+ if (!featureIds) {
2777
+ return;
2778
+ }
2779
+ for (const featureId of featureIds) {
2780
+ let featureIdData = null;
2781
+ if (typeof featureId.attribute !== "undefined") {
2782
+ const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
2783
+ const accessorIndex = primitive.attributes[accessorKey];
2784
+ featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
2785
+ } else if (typeof featureId.texture !== "undefined" && options?.gltf?.loadImages) {
2786
+ featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
2787
+ } else {
2788
+ }
2789
+ featureId.data = featureIdData;
2790
+ }
2791
+ }
2792
+ var EXT_MESH_FEATURES_NAME, name;
2793
+ var init_EXT_mesh_features = __esm({
2794
+ "src/lib/extensions/EXT_mesh_features.ts"() {
2795
+ init_gltf_scenegraph();
2796
+ init_d_tiles_utils();
2797
+ EXT_MESH_FEATURES_NAME = "EXT_mesh_features";
2798
+ name = EXT_MESH_FEATURES_NAME;
2799
+ }
2800
+ });
2801
+
2694
2802
  // src/lib/extensions/EXT_structural_metadata.ts
2695
2803
  var EXT_structural_metadata_exports = {};
2696
2804
  __export(EXT_structural_metadata_exports, {
2697
- decode: () => decode,
2805
+ decode: () => decode2,
2806
+ getPropertyTableFromExtStructuralMetadata: () => getPropertyTableFromExtStructuralMetadata,
2698
2807
  getPropertyTablePopulated: () => getPropertyTablePopulated,
2699
- name: () => name
2808
+ name: () => name2
2700
2809
  });
2701
- async function decode(gltfData, options) {
2810
+ async function decode2(gltfData, options) {
2702
2811
  const scenegraph = new GLTFScenegraph(gltfData);
2703
2812
  decodeExtStructuralMetadata(scenegraph, options);
2704
2813
  }
2814
+ function getPropertyTableFromExtStructuralMetadata(extension, metadataClass) {
2815
+ if (extension.propertyTables) {
2816
+ const firstPropertyTable = extension?.propertyTables[0];
2817
+ const propertyTableWithData = {};
2818
+ for (const propertyName in firstPropertyTable.properties) {
2819
+ propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;
2820
+ }
2821
+ return propertyTableWithData;
2822
+ }
2823
+ if (extension.propertyTextures) {
2824
+ const firstPropertyTexture = extension?.propertyTextures[0];
2825
+ const propertyTableWithData = {};
2826
+ for (const propertyName in firstPropertyTexture.properties) {
2827
+ propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;
2828
+ }
2829
+ return propertyTableWithData;
2830
+ }
2831
+ console.warn("Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension.");
2832
+ return null;
2833
+ }
2705
2834
  function getPropertyTablePopulated(scenegraph, propertyTableIndex) {
2706
2835
  const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
2707
2836
  const propertyTable = extension?.propertyTables?.[propertyTableIndex];
@@ -2712,33 +2841,47 @@
2712
2841
  throw new Error(`Incorrect data in the EXT_structural_metadata extension: no property table with index ${propertyTableIndex}`);
2713
2842
  }
2714
2843
  function decodeExtStructuralMetadata(scenegraph, options) {
2844
+ if (!options.gltf?.loadBuffers) {
2845
+ return;
2846
+ }
2715
2847
  const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
2716
- if (!extension?.schema) {
2848
+ if (!extension) {
2717
2849
  return;
2718
2850
  }
2851
+ if (options.gltf?.loadImages) {
2852
+ decodePropertyTextures(scenegraph, extension);
2853
+ }
2854
+ decodePropertyTables(scenegraph, extension);
2855
+ }
2856
+ function decodePropertyTextures(scenegraph, extension) {
2719
2857
  const propertyTextures = extension.propertyTextures;
2720
2858
  const json = scenegraph.gltf.json;
2721
- if (propertyTextures && json.meshes && options?.gltf?.loadImages) {
2859
+ if (propertyTextures && json.meshes) {
2722
2860
  for (const mesh of json.meshes) {
2723
2861
  for (const primitive of mesh.primitives) {
2724
2862
  processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
2725
2863
  }
2726
2864
  }
2727
2865
  }
2728
- const schemaClasses = extension.schema.classes;
2866
+ }
2867
+ function decodePropertyTables(scenegraph, extension) {
2868
+ const schema = extension.schema;
2869
+ if (!schema) {
2870
+ return;
2871
+ }
2872
+ const schemaClasses = schema.classes;
2729
2873
  const propertyTables = extension.propertyTables;
2730
2874
  if (schemaClasses && propertyTables) {
2731
2875
  for (const schemaName in schemaClasses) {
2732
2876
  const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
2733
2877
  if (propertyTable) {
2734
- processPropertyTable(scenegraph, extension.schema, propertyTable);
2878
+ processPropertyTable(scenegraph, schema, propertyTable);
2735
2879
  }
2736
2880
  }
2737
2881
  }
2738
2882
  }
2739
2883
  function findPropertyTableByClass(propertyTables, schemaClassName) {
2740
- for (let i2 = 0, len = propertyTables.length; i2 < len; i2++) {
2741
- const propertyTable = propertyTables[i2];
2884
+ for (const propertyTable of propertyTables) {
2742
2885
  if (propertyTable.class === schemaClassName) {
2743
2886
  return propertyTable;
2744
2887
  }
@@ -2767,9 +2910,9 @@
2767
2910
  extension.dataAttributeNames = [];
2768
2911
  }
2769
2912
  const className = propertyTexture.class;
2770
- for (const propName in propertyTexture.properties) {
2771
- const attributeName = `${className}_${propName}`;
2772
- const textureInfoTopLevel = propertyTexture.properties?.[propName];
2913
+ for (const propertyName in propertyTexture.properties) {
2914
+ const attributeName = `${className}_${propertyName}`;
2915
+ const textureInfoTopLevel = propertyTexture.properties?.[propertyName];
2773
2916
  if (!textureInfoTopLevel) {
2774
2917
  continue;
2775
2918
  }
@@ -2835,14 +2978,14 @@
2835
2978
  return data;
2836
2979
  }
2837
2980
  function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
2838
- if (classProperty.array && typeof classProperty.count === "undefined" && typeof propertyTableProperty.arrayOffsets !== "undefined" && typeof propertyTableProperty.arrayOffsetType !== "undefined") {
2839
- return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType, numberOfElements);
2981
+ if (classProperty.array && typeof classProperty.count === "undefined" && typeof propertyTableProperty.arrayOffsets !== "undefined") {
2982
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || "UINT32", numberOfElements);
2840
2983
  }
2841
2984
  return null;
2842
2985
  }
2843
2986
  function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
2844
- if (typeof propertyTableProperty.stringOffsets !== "undefined" && typeof propertyTableProperty.stringOffsetType !== "undefined") {
2845
- return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType, numberOfElements);
2987
+ if (typeof propertyTableProperty.stringOffsets !== "undefined") {
2988
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || "UINT32", numberOfElements);
2846
2989
  }
2847
2990
  return null;
2848
2991
  }
@@ -3006,79 +3149,13 @@
3006
3149
  }
3007
3150
  return null;
3008
3151
  }
3009
- var EXT_STRUCTURAL_METADATA_NAME, name;
3152
+ var EXT_STRUCTURAL_METADATA_NAME, name2;
3010
3153
  var init_EXT_structural_metadata = __esm({
3011
3154
  "src/lib/extensions/EXT_structural_metadata.ts"() {
3012
3155
  init_gltf_scenegraph();
3013
3156
  init_d_tiles_utils();
3014
3157
  EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
3015
- name = EXT_STRUCTURAL_METADATA_NAME;
3016
- }
3017
- });
3018
-
3019
- // src/lib/extensions/EXT_mesh_features.ts
3020
- var EXT_mesh_features_exports = {};
3021
- __export(EXT_mesh_features_exports, {
3022
- decode: () => decode2,
3023
- name: () => name2
3024
- });
3025
- async function decode2(gltfData, options) {
3026
- const scenegraph = new GLTFScenegraph(gltfData);
3027
- decodeExtMeshFeatures(scenegraph, options);
3028
- }
3029
- function decodeExtMeshFeatures(scenegraph, options) {
3030
- const json = scenegraph.gltf.json;
3031
- if (!json.meshes) {
3032
- return;
3033
- }
3034
- for (const mesh of json.meshes) {
3035
- for (const primitive of mesh.primitives) {
3036
- processMeshPrimitiveFeatures(scenegraph, primitive, options);
3037
- }
3038
- }
3039
- }
3040
- function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
3041
- const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
3042
- const featureIds = extension?.featureIds;
3043
- if (!featureIds)
3044
- return;
3045
- if (!extension.dataAttributeNames) {
3046
- extension.dataAttributeNames = [];
3047
- }
3048
- let featureIdCount = 0;
3049
- for (const featureId of featureIds) {
3050
- let propertyTable = null;
3051
- if (typeof featureId.propertyTable === "number") {
3052
- propertyTable = getPropertyTablePopulated(scenegraph, featureId.propertyTable);
3053
- }
3054
- let propertyData = null;
3055
- if (typeof featureId.attribute !== "undefined") {
3056
- const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
3057
- const accessorIndex = primitive.attributes[accessorKey];
3058
- const propertyDataTypedArray = scenegraph.getTypedArrayForAccessor(accessorIndex);
3059
- propertyData = Array.prototype.slice.call(propertyDataTypedArray);
3060
- } else if (typeof featureId.texture !== "undefined" && options?.gltf?.loadImages) {
3061
- propertyData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
3062
- } else {
3063
- }
3064
- const attributeName = featureId.label || propertyTable?.name || `featureAttribute${featureIdCount}`;
3065
- const featureTable = [];
3066
- if (propertyData) {
3067
- primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive);
3068
- }
3069
- extension.dataAttributeNames.push(attributeName);
3070
- featureId.data = featureTable;
3071
- featureIdCount++;
3072
- }
3073
- }
3074
- var EXT_MESH_FEATURES_NAME, name2;
3075
- var init_EXT_mesh_features = __esm({
3076
- "src/lib/extensions/EXT_mesh_features.ts"() {
3077
- init_gltf_scenegraph();
3078
- init_d_tiles_utils();
3079
- init_EXT_structural_metadata();
3080
- EXT_MESH_FEATURES_NAME = "EXT_mesh_features";
3081
- name2 = EXT_MESH_FEATURES_NAME;
3158
+ name2 = EXT_STRUCTURAL_METADATA_NAME;
3082
3159
  }
3083
3160
  });
3084
3161
 
@@ -3086,12 +3163,45 @@
3086
3163
  var EXT_feature_metadata_exports = {};
3087
3164
  __export(EXT_feature_metadata_exports, {
3088
3165
  decode: () => decode3,
3166
+ getPropertyTableFromExtFeatureMetadata: () => getPropertyTableFromExtFeatureMetadata,
3089
3167
  name: () => name3
3090
3168
  });
3091
3169
  async function decode3(gltfData, options) {
3092
3170
  const scenegraph = new GLTFScenegraph(gltfData);
3093
3171
  decodeExtFeatureMetadata(scenegraph, options);
3094
3172
  }
3173
+ function getPropertyTableFromExtFeatureMetadata(extension, metadataClass) {
3174
+ if (extension.featureTables) {
3175
+ const firstFeatureTableName = Object.keys(extension.featureTables)?.[0];
3176
+ if (firstFeatureTableName) {
3177
+ const featureTable = extension.featureTables[firstFeatureTableName];
3178
+ const propertyTable = {};
3179
+ for (const propertyName in featureTable.properties) {
3180
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
3181
+ }
3182
+ return propertyTable;
3183
+ }
3184
+ }
3185
+ if (extension.featureTextures) {
3186
+ let featureTexture;
3187
+ for (const textureKey in extension.featureTextures) {
3188
+ const texture = extension.featureTextures[textureKey];
3189
+ if (texture.class === metadataClass) {
3190
+ featureTexture = textureKey;
3191
+ }
3192
+ }
3193
+ if (typeof featureTexture === "string") {
3194
+ const featureTable = extension.featureTextures[featureTexture];
3195
+ const propertyTable = {};
3196
+ for (const propertyName in featureTable.properties) {
3197
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
3198
+ }
3199
+ return propertyTable;
3200
+ }
3201
+ }
3202
+ console.warn("Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension.");
3203
+ return null;
3204
+ }
3095
3205
  function decodeExtFeatureMetadata(scenegraph, options) {
3096
3206
  const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
3097
3207
  if (!extension)
@@ -3197,9 +3307,10 @@
3197
3307
  const textureData = [];
3198
3308
  const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
3199
3309
  const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
3200
- const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
3201
- const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
3202
- const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
3310
+ const textureCoordinates = getFloat32ArrayForAccessor(scenegraph.gltf, texCoordAccessorIndex);
3311
+ if (!textureCoordinates) {
3312
+ return;
3313
+ }
3203
3314
  const textureIndex = featureTextureProperty.texture.index;
3204
3315
  const texture = json.textures?.[textureIndex];
3205
3316
  const imageIndex = texture?.source;
@@ -3317,18 +3428,18 @@
3317
3428
  });
3318
3429
 
3319
3430
  // src/lib/utils/version.ts
3320
- var VERSION4;
3431
+ var VERSION3;
3321
3432
  var init_version3 = __esm({
3322
3433
  "src/lib/utils/version.ts"() {
3323
- VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3434
+ VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
3324
3435
  }
3325
3436
  });
3326
3437
 
3327
3438
  // ../textures/src/lib/utils/version.ts
3328
- var VERSION5;
3439
+ var VERSION4;
3329
3440
  var init_version4 = __esm({
3330
3441
  "../textures/src/lib/utils/version.ts"() {
3331
- VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
3442
+ VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
3332
3443
  }
3333
3444
  });
3334
3445
 
@@ -3767,7 +3878,7 @@
3767
3878
  name: "Basis",
3768
3879
  id: "basis",
3769
3880
  module: "textures",
3770
- version: VERSION5,
3881
+ version: VERSION4,
3771
3882
  worker: true,
3772
3883
  extensions: ["basis", "ktx2"],
3773
3884
  mimeTypes: ["application/octet-stream", "image/ktx2"],
@@ -4243,10 +4354,10 @@
4243
4354
  });
4244
4355
 
4245
4356
  // ../draco/src/lib/utils/version.ts
4246
- var VERSION6;
4357
+ var VERSION5;
4247
4358
  var init_version5 = __esm({
4248
4359
  "../draco/src/lib/utils/version.ts"() {
4249
- VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
4360
+ VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
4250
4361
  }
4251
4362
  });
4252
4363
 
@@ -4267,7 +4378,7 @@
4267
4378
  name: "Draco",
4268
4379
  id: "draco",
4269
4380
  module: "draco",
4270
- version: VERSION6,
4381
+ version: VERSION5,
4271
4382
  worker: true,
4272
4383
  extensions: ["drc"],
4273
4384
  mimeTypes: ["application/octet-stream"],
@@ -5022,30 +5133,6 @@
5022
5133
  }
5023
5134
  });
5024
5135
 
5025
- // src/lib/gltf-utils/gltf-constants.ts
5026
- var COMPONENTS, BYTES;
5027
- var init_gltf_constants = __esm({
5028
- "src/lib/gltf-utils/gltf-constants.ts"() {
5029
- COMPONENTS = {
5030
- SCALAR: 1,
5031
- VEC2: 2,
5032
- VEC3: 3,
5033
- VEC4: 4,
5034
- MAT2: 4,
5035
- MAT3: 9,
5036
- MAT4: 16
5037
- };
5038
- BYTES = {
5039
- 5120: 1,
5040
- 5121: 1,
5041
- 5122: 2,
5042
- 5123: 2,
5043
- 5125: 4,
5044
- 5126: 4
5045
- };
5046
- }
5047
- });
5048
-
5049
5136
  // src/lib/extensions/KHR_texture_transform.ts
5050
5137
  var KHR_texture_transform_exports = {};
5051
5138
  __export(KHR_texture_transform_exports, {
@@ -5401,8 +5488,8 @@
5401
5488
  init_KHR_techniques_webgl();
5402
5489
  init_EXT_feature_metadata();
5403
5490
  EXTENSIONS2 = [
5404
- EXT_mesh_features_exports,
5405
5491
  EXT_structural_metadata_exports,
5492
+ EXT_mesh_features_exports,
5406
5493
  EXT_meshopt_compression_exports,
5407
5494
  EXT_texture_webp_exports,
5408
5495
  KHR_texture_basisu_exports,
@@ -5794,7 +5881,7 @@
5794
5881
  name: "glTF",
5795
5882
  id: "gltf",
5796
5883
  module: "gltf",
5797
- version: VERSION4,
5884
+ version: VERSION3,
5798
5885
  extensions: ["gltf", "glb"],
5799
5886
  mimeTypes: ["model/gltf+json", "model/gltf-binary"],
5800
5887
  text: true,
@@ -5911,7 +5998,7 @@
5911
5998
  name: "glTF",
5912
5999
  id: "gltf",
5913
6000
  module: "gltf",
5914
- version: VERSION4,
6001
+ version: VERSION3,
5915
6002
  extensions: ["glb"],
5916
6003
  mimeTypes: ["model/gltf-binary"],
5917
6004
  binary: true,
@@ -5942,7 +6029,7 @@
5942
6029
  name: "GLB",
5943
6030
  id: "glb",
5944
6031
  module: "gltf",
5945
- version: VERSION4,
6032
+ version: VERSION3,
5946
6033
  extensions: ["glb"],
5947
6034
  mimeTypes: ["model/gltf-binary"],
5948
6035
  binary: true,
@@ -5975,7 +6062,7 @@
5975
6062
  name: "GLB",
5976
6063
  id: "glb",
5977
6064
  module: "gltf",
5978
- version: VERSION4,
6065
+ version: VERSION3,
5979
6066
  extensions: ["glb"],
5980
6067
  mimeTypes: ["model/gltf-binary"],
5981
6068
  binary: true,
@@ -6365,14 +6452,16 @@
6365
6452
  var src_exports = {};
6366
6453
  __export(src_exports, {
6367
6454
  EXT_FEATURE_METADATA: () => name3,
6368
- EXT_MESH_FEATURES: () => name2,
6369
- EXT_STRUCTURAL_METADATA: () => name,
6455
+ EXT_MESH_FEATURES: () => name,
6456
+ EXT_STRUCTURAL_METADATA: () => name2,
6370
6457
  GLBLoader: () => GLBLoader,
6371
6458
  GLBWriter: () => GLBWriter,
6372
6459
  GLTFLoader: () => GLTFLoader,
6373
6460
  GLTFScenegraph: () => GLTFScenegraph,
6374
6461
  GLTFWriter: () => GLTFWriter,
6375
6462
  _getMemoryUsageGLTF: () => getMemoryUsageGLTF,
6463
+ getPropertyTableFromExtFeatureMetadata: () => getPropertyTableFromExtFeatureMetadata,
6464
+ getPropertyTableFromExtStructuralMetadata: () => getPropertyTableFromExtStructuralMetadata,
6376
6465
  postProcessGLTF: () => postProcessGLTF
6377
6466
  });
6378
6467
  var init_src8 = __esm({
@@ -6380,6 +6469,8 @@
6380
6469
  init_EXT_mesh_features();
6381
6470
  init_EXT_structural_metadata();
6382
6471
  init_EXT_feature_metadata();
6472
+ init_EXT_feature_metadata();
6473
+ init_EXT_structural_metadata();
6383
6474
  init_gltf_loader();
6384
6475
  init_gltf_writer();
6385
6476
  init_glb_loader();
package/dist/es5/index.js CHANGED
@@ -57,6 +57,18 @@ Object.defineProperty(exports, "_getMemoryUsageGLTF", {
57
57
  return _gltfUtils.getMemoryUsageGLTF;
58
58
  }
59
59
  });
60
+ Object.defineProperty(exports, "getPropertyTableFromExtFeatureMetadata", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _EXT_feature_metadata.getPropertyTableFromExtFeatureMetadata;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "getPropertyTableFromExtStructuralMetadata", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _EXT_structural_metadata.getPropertyTableFromExtStructuralMetadata;
70
+ }
71
+ });
60
72
  Object.defineProperty(exports, "postProcessGLTF", {
61
73
  enumerable: true,
62
74
  get: function get() {