@deck.gl/geo-layers 9.3.4 → 9.3.6

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.
package/dist/dist.dev.js CHANGED
@@ -11232,7 +11232,7 @@ var __exports__ = (() => {
11232
11232
  }
11233
11233
 
11234
11234
  // ../../node_modules/@loaders.gl/xml/dist/xml-loader.js
11235
- var VERSION = true ? "4.4.1" : "latest";
11235
+ var VERSION = true ? "4.4.3" : "latest";
11236
11236
  var XMLLoader = {
11237
11237
  dataType: null,
11238
11238
  batchType: null,
@@ -11815,7 +11815,7 @@ var __exports__ = (() => {
11815
11815
  var dist_default = new ProbeLog({ id: "@probe.gl/log" });
11816
11816
 
11817
11817
  // ../../node_modules/@loaders.gl/loader-utils/dist/lib/log-utils/log.js
11818
- var VERSION3 = true ? "4.4.1" : "latest";
11818
+ var VERSION3 = true ? "4.4.3" : "latest";
11819
11819
  var version = VERSION3[0] >= "0" && VERSION3[0] <= "9" ? `v${VERSION3}` : "";
11820
11820
  function createLog() {
11821
11821
  const log8 = new ProbeLog({ id: "loaders.gl" });
@@ -11870,7 +11870,7 @@ var __exports__ = (() => {
11870
11870
  globalThis._loadersgl_.version = NPM_TAG;
11871
11871
  warningIssued = true;
11872
11872
  } else {
11873
- globalThis._loadersgl_.version = "4.4.1";
11873
+ globalThis._loadersgl_.version = "4.4.3";
11874
11874
  }
11875
11875
  }
11876
11876
  return globalThis._loadersgl_.version;
@@ -12716,7 +12716,7 @@ var __exports__ = (() => {
12716
12716
  }
12717
12717
 
12718
12718
  // ../../node_modules/@loaders.gl/wms/dist/wms-error-loader.js
12719
- var VERSION5 = true ? "4.4.1" : "latest";
12719
+ var VERSION5 = true ? "4.4.3" : "latest";
12720
12720
  var WMSErrorLoader = {
12721
12721
  dataType: null,
12722
12722
  batchType: null,
@@ -12995,7 +12995,7 @@ var __exports__ = (() => {
12995
12995
  }
12996
12996
 
12997
12997
  // ../../node_modules/@loaders.gl/wms/dist/wms-capabilities-loader.js
12998
- var VERSION6 = true ? "4.4.1" : "latest";
12998
+ var VERSION6 = true ? "4.4.3" : "latest";
12999
12999
  var WMSCapabilitiesLoader = {
13000
13000
  dataType: null,
13001
13001
  batchType: null,
@@ -13068,7 +13068,7 @@ var __exports__ = (() => {
13068
13068
  };
13069
13069
 
13070
13070
  // ../../node_modules/@loaders.gl/images/dist/lib/utils/version.js
13071
- var VERSION7 = true ? "4.4.1" : "latest";
13071
+ var VERSION7 = true ? "4.4.3" : "latest";
13072
13072
 
13073
13073
  // ../../node_modules/@loaders.gl/images/dist/lib/category-api/image-type.js
13074
13074
  var parseImageNode = globalThis.loaders?.parseImageNode;
@@ -16586,591 +16586,6 @@ out float vTime;
16586
16586
  var import_layers8 = __toESM(require_layers(), 1);
16587
16587
  var import_mesh_layers2 = __toESM(require_mesh_layers(), 1);
16588
16588
 
16589
- // ../../node_modules/@loaders.gl/textures/dist/lib/utils/version.js
16590
- var VERSION8 = true ? "4.4.1" : "latest";
16591
-
16592
- // ../../node_modules/@loaders.gl/textures/dist/lib/parsers/basis-module-loader.js
16593
- var BASIS_EXTERNAL_LIBRARIES = {
16594
- /** Basis transcoder, javascript wrapper part */
16595
- TRANSCODER: "basis_transcoder.js",
16596
- /** Basis transcoder, compiled web assembly part */
16597
- TRANSCODER_WASM: "basis_transcoder.wasm",
16598
- /** Basis encoder, javascript wrapper part */
16599
- ENCODER: "basis_encoder.js",
16600
- /** Basis encoder, compiled web assembly part */
16601
- ENCODER_WASM: "basis_encoder.wasm"
16602
- };
16603
- var loadBasisTranscoderPromise;
16604
- async function loadBasisTranscoderModule(options) {
16605
- registerJSModules(options.modules);
16606
- const basis = getJSModuleOrNull("basis");
16607
- if (basis) {
16608
- return basis;
16609
- }
16610
- loadBasisTranscoderPromise ||= loadBasisTranscoder(options);
16611
- return await loadBasisTranscoderPromise;
16612
- }
16613
- async function loadBasisTranscoder(options) {
16614
- let BASIS2 = null;
16615
- let wasmBinary = null;
16616
- [BASIS2, wasmBinary] = await Promise.all([
16617
- await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, "textures", options),
16618
- await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, "textures", options)
16619
- ]);
16620
- BASIS2 = BASIS2 || globalThis.BASIS;
16621
- return await initializeBasisTranscoderModule(BASIS2, wasmBinary);
16622
- }
16623
- function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
16624
- const options = {};
16625
- if (wasmBinary) {
16626
- options.wasmBinary = wasmBinary;
16627
- }
16628
- return new Promise((resolve2) => {
16629
- BasisModule(options).then((module) => {
16630
- const { BasisFile, initializeBasis } = module;
16631
- initializeBasis();
16632
- resolve2({ BasisFile });
16633
- });
16634
- });
16635
- }
16636
- var loadBasisEncoderPromise;
16637
- async function loadBasisEncoderModule(options) {
16638
- const modules = options.modules || {};
16639
- if (modules.basisEncoder) {
16640
- return modules.basisEncoder;
16641
- }
16642
- loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
16643
- return await loadBasisEncoderPromise;
16644
- }
16645
- async function loadBasisEncoder(options) {
16646
- let BASIS_ENCODER = null;
16647
- let wasmBinary = null;
16648
- [BASIS_ENCODER, wasmBinary] = await Promise.all([
16649
- await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, "textures", options),
16650
- await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, "textures", options)
16651
- ]);
16652
- BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
16653
- return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
16654
- }
16655
- function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
16656
- const options = {};
16657
- if (wasmBinary) {
16658
- options.wasmBinary = wasmBinary;
16659
- }
16660
- return new Promise((resolve2) => {
16661
- BasisEncoderModule(options).then((module) => {
16662
- const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
16663
- initializeBasis();
16664
- resolve2({ BasisFile, KTX2File, BasisEncoder });
16665
- });
16666
- });
16667
- }
16668
-
16669
- // ../../node_modules/@loaders.gl/textures/dist/lib/gl-extensions.js
16670
- var GL_RGBA4 = 32854;
16671
- var GL_RGBA8 = 32856;
16672
- var GL_RGB565 = 36194;
16673
- var GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
16674
- var GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
16675
- var GL_COMPRESSED_RGBA8_ETC2_EAC = 37493;
16676
- var GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840;
16677
- var GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842;
16678
- var GL_COMPRESSED_RGB_ETC1_WEBGL = 36196;
16679
- var GL_COMPRESSED_RGB_ATC_WEBGL = 35986;
16680
- var GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798;
16681
- var GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808;
16682
- var GL_COMPRESSED_RED_RGTC1_EXT = 36283;
16683
- var GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 36285;
16684
- var GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 36492;
16685
-
16686
- // ../../node_modules/@loaders.gl/textures/dist/lib/utils/detect-supported-texture-formats.js
16687
- var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
16688
- var WEBGL_TEXTURE_FORMATS = {
16689
- /* eslint-disable camelcase */
16690
- WEBGL_compressed_texture_s3tc: [
16691
- "bc1-rgb-unorm-webgl",
16692
- "bc1-rgba-unorm",
16693
- "bc2-rgba-unorm",
16694
- "bc3-rgba-unorm"
16695
- ],
16696
- WEBGL_compressed_texture_s3tc_srgb: [
16697
- "bc1-rgb-unorm-srgb-webgl",
16698
- "bc1-rgba-unorm-srgb",
16699
- "bc2-rgba-unorm-srgb",
16700
- "bc3-rgba-unorm-srgb"
16701
- ],
16702
- EXT_texture_compression_rgtc: ["bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm"],
16703
- EXT_texture_compression_bptc: [
16704
- "bc6h-rgb-ufloat",
16705
- "bc6h-rgb-float",
16706
- "bc7-rgba-unorm",
16707
- "bc7-rgba-unorm-srgb"
16708
- ],
16709
- WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
16710
- WEBGL_compressed_texture_etc: [
16711
- "etc2-rgb8unorm",
16712
- "etc2-rgb8unorm-srgb",
16713
- "etc2-rgb8a1unorm",
16714
- "etc2-rgb8a1unorm-srgb",
16715
- "etc2-rgba8unorm",
16716
- "etc2-rgba8unorm-srgb",
16717
- "eac-r11unorm",
16718
- "eac-r11snorm",
16719
- "eac-rg11unorm",
16720
- "eac-rg11snorm"
16721
- ],
16722
- WEBGL_compressed_texture_pvrtc: [
16723
- "pvrtc-rgb4unorm-webgl",
16724
- "pvrtc-rgba4unorm-webgl",
16725
- "pvrtc-rgb2unorm-webgl",
16726
- "pvrtc-rgba2unorm-webgl"
16727
- ],
16728
- WEBGL_compressed_texture_atc: [
16729
- "atc-rgb-unorm-webgl",
16730
- "atc-rgba-unorm-webgl",
16731
- "atc-rgbai-unorm-webgl"
16732
- ],
16733
- WEBGL_compressed_texture_astc: [
16734
- "astc-4x4-unorm",
16735
- "astc-4x4-unorm-srgb",
16736
- "astc-5x4-unorm",
16737
- "astc-5x4-unorm-srgb",
16738
- "astc-5x5-unorm",
16739
- "astc-5x5-unorm-srgb",
16740
- "astc-6x5-unorm",
16741
- "astc-6x5-unorm-srgb",
16742
- "astc-6x6-unorm",
16743
- "astc-6x6-unorm-srgb",
16744
- "astc-8x5-unorm",
16745
- "astc-8x5-unorm-srgb",
16746
- "astc-8x6-unorm",
16747
- "astc-8x6-unorm-srgb",
16748
- "astc-8x8-unorm",
16749
- "astc-8x8-unorm-srgb",
16750
- "astc-10x5-unorm",
16751
- "astc-10x5-unorm-srgb",
16752
- "astc-10x6-unorm",
16753
- "astc-10x6-unorm-srgb",
16754
- "astc-10x8-unorm",
16755
- "astc-10x8-unorm-srgb",
16756
- "astc-10x10-unorm",
16757
- "astc-10x10-unorm-srgb",
16758
- "astc-12x10-unorm",
16759
- "astc-12x10-unorm-srgb",
16760
- "astc-12x12-unorm",
16761
- "astc-12x12-unorm-srgb"
16762
- ]
16763
- /* eslint-enable camelcase */
16764
- };
16765
- var textureFormats = null;
16766
- function detectSupportedTextureFormats(gl) {
16767
- if (!textureFormats) {
16768
- gl = gl || getWebGLContext() || void 0;
16769
- textureFormats = /* @__PURE__ */ new Set();
16770
- for (const prefix of BROWSER_PREFIXES) {
16771
- for (const extension in WEBGL_TEXTURE_FORMATS) {
16772
- if (gl && gl.getExtension(`${prefix}${extension}`)) {
16773
- for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
16774
- textureFormats.add(textureFormat);
16775
- }
16776
- }
16777
- }
16778
- }
16779
- }
16780
- return textureFormats;
16781
- }
16782
- function getWebGLContext() {
16783
- try {
16784
- const canvas = document.createElement("canvas");
16785
- return canvas.getContext("webgl");
16786
- } catch (error) {
16787
- return null;
16788
- }
16789
- }
16790
-
16791
- // ../../node_modules/@loaders.gl/textures/dist/lib/parsers/parse-ktx.js
16792
- var KTX2_ID = [
16793
- // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
16794
- 171,
16795
- 75,
16796
- 84,
16797
- 88,
16798
- 32,
16799
- 50,
16800
- 48,
16801
- 187,
16802
- 13,
16803
- 10,
16804
- 26,
16805
- 10
16806
- ];
16807
- function isKTX(data) {
16808
- const id = new Uint8Array(data);
16809
- const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || // '´'
16810
- id[1] !== KTX2_ID[1] || // 'K'
16811
- id[2] !== KTX2_ID[2] || // 'T'
16812
- id[3] !== KTX2_ID[3] || // 'X'
16813
- id[4] !== KTX2_ID[4] || // ' '
16814
- id[5] !== KTX2_ID[5] || // '2'
16815
- id[6] !== KTX2_ID[6] || // '0'
16816
- id[7] !== KTX2_ID[7] || // 'ª'
16817
- id[8] !== KTX2_ID[8] || // '\r'
16818
- id[9] !== KTX2_ID[9] || // '\n'
16819
- id[10] !== KTX2_ID[10] || // '\x1A'
16820
- id[11] !== KTX2_ID[11];
16821
- return !notKTX;
16822
- }
16823
-
16824
- // ../../node_modules/@loaders.gl/textures/dist/lib/parsers/parse-basis.js
16825
- var basisTranscodingLock = Promise.resolve();
16826
- var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
16827
- etc1: {
16828
- basisFormat: 0,
16829
- compressed: true,
16830
- format: GL_COMPRESSED_RGB_ETC1_WEBGL,
16831
- textureFormat: "etc1-rgb-unorm-webgl"
16832
- },
16833
- etc2: {
16834
- basisFormat: 1,
16835
- compressed: true,
16836
- format: GL_COMPRESSED_RGBA8_ETC2_EAC,
16837
- textureFormat: "etc2-rgba8unorm"
16838
- },
16839
- bc1: {
16840
- basisFormat: 2,
16841
- compressed: true,
16842
- format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
16843
- textureFormat: "bc1-rgb-unorm-webgl"
16844
- },
16845
- bc3: {
16846
- basisFormat: 3,
16847
- compressed: true,
16848
- format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
16849
- textureFormat: "bc3-rgba-unorm"
16850
- },
16851
- bc4: {
16852
- basisFormat: 4,
16853
- compressed: true,
16854
- format: GL_COMPRESSED_RED_RGTC1_EXT,
16855
- textureFormat: "bc4-r-unorm"
16856
- },
16857
- bc5: {
16858
- basisFormat: 5,
16859
- compressed: true,
16860
- format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
16861
- textureFormat: "bc5-rg-unorm"
16862
- },
16863
- "bc7-m6-opaque-only": {
16864
- basisFormat: 6,
16865
- compressed: true,
16866
- format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
16867
- textureFormat: "bc7-rgba-unorm"
16868
- },
16869
- "bc7-m5": {
16870
- basisFormat: 7,
16871
- compressed: true,
16872
- format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
16873
- textureFormat: "bc7-rgba-unorm"
16874
- },
16875
- "pvrtc1-4-rgb": {
16876
- basisFormat: 8,
16877
- compressed: true,
16878
- format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
16879
- textureFormat: "pvrtc-rgb4unorm-webgl"
16880
- },
16881
- "pvrtc1-4-rgba": {
16882
- basisFormat: 9,
16883
- compressed: true,
16884
- format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
16885
- textureFormat: "pvrtc-rgba4unorm-webgl"
16886
- },
16887
- "astc-4x4": {
16888
- basisFormat: 10,
16889
- compressed: true,
16890
- format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
16891
- textureFormat: "astc-4x4-unorm"
16892
- },
16893
- "atc-rgb": {
16894
- basisFormat: 11,
16895
- compressed: true,
16896
- format: GL_COMPRESSED_RGB_ATC_WEBGL,
16897
- textureFormat: "atc-rgb-unorm-webgl"
16898
- },
16899
- "atc-rgba-interpolated-alpha": {
16900
- basisFormat: 12,
16901
- compressed: true,
16902
- format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
16903
- textureFormat: "atc-rgbai-unorm-webgl"
16904
- },
16905
- rgba32: {
16906
- basisFormat: 13,
16907
- compressed: false,
16908
- format: GL_RGBA8,
16909
- textureFormat: "rgba8unorm"
16910
- },
16911
- rgb565: {
16912
- basisFormat: 14,
16913
- compressed: false,
16914
- format: GL_RGB565,
16915
- textureFormat: "rgb565unorm-webgl"
16916
- },
16917
- bgr565: {
16918
- basisFormat: 15,
16919
- compressed: false,
16920
- format: GL_RGB565,
16921
- textureFormat: "rgb565unorm-webgl"
16922
- },
16923
- rgba4444: {
16924
- basisFormat: 16,
16925
- compressed: false,
16926
- format: GL_RGBA4,
16927
- textureFormat: "rgba4unorm-webgl"
16928
- }
16929
- };
16930
- var BASIS_FORMATS = Object.freeze(Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS));
16931
- async function withBasisTranscodingLock(transcode) {
16932
- const previousLock = basisTranscodingLock;
16933
- let releaseLock;
16934
- basisTranscodingLock = new Promise((resolve2) => {
16935
- releaseLock = resolve2;
16936
- });
16937
- await previousLock;
16938
- try {
16939
- return await transcode();
16940
- } finally {
16941
- releaseLock();
16942
- }
16943
- }
16944
- async function parseBasis(data, options = {}) {
16945
- const loadLibraryOptions = extractLoadLibraryOptions(options);
16946
- return await withBasisTranscodingLock(async () => {
16947
- if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
16948
- if (isKTX(data)) {
16949
- const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
16950
- return parseKTX2File(fileConstructors.KTX2File, data, options);
16951
- }
16952
- const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
16953
- return parseBasisFile(BasisFile, data, options);
16954
- }
16955
- switch (options.basis.module) {
16956
- case "encoder":
16957
- const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
16958
- switch (options.basis.containerFormat) {
16959
- case "ktx2":
16960
- return parseKTX2File(fileConstructors.KTX2File, data, options);
16961
- case "basis":
16962
- default:
16963
- return parseBasisFile(fileConstructors.BasisFile, data, options);
16964
- }
16965
- case "transcoder":
16966
- default:
16967
- const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
16968
- return parseBasisFile(BasisFile, data, options);
16969
- }
16970
- });
16971
- }
16972
- function parseBasisFile(BasisFile, data, options) {
16973
- const basisFile = new BasisFile(new Uint8Array(data));
16974
- try {
16975
- if (!basisFile.startTranscoding()) {
16976
- throw new Error("Failed to start basis transcoding");
16977
- }
16978
- const imageCount = basisFile.getNumImages();
16979
- const images = [];
16980
- for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
16981
- const levelsCount = basisFile.getNumLevels(imageIndex);
16982
- const levels = [];
16983
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
16984
- levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
16985
- }
16986
- images.push(levels);
16987
- }
16988
- return images;
16989
- } finally {
16990
- basisFile.close();
16991
- basisFile.delete();
16992
- }
16993
- }
16994
- function transcodeImage(basisFile, imageIndex, levelIndex, options) {
16995
- const width = basisFile.getImageWidth(imageIndex, levelIndex);
16996
- const height = basisFile.getImageHeight(imageIndex, levelIndex);
16997
- const hasAlpha = basisFile.getHasAlpha(
16998
- /* imageIndex, levelIndex */
16999
- );
17000
- const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
17001
- const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
17002
- const decodedData = new Uint8Array(decodedSize);
17003
- if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
17004
- throw new Error("failed to start Basis transcoding");
17005
- }
17006
- return {
17007
- // standard loaders.gl image category payload
17008
- shape: "texture-level",
17009
- width,
17010
- height,
17011
- data: decodedData,
17012
- compressed,
17013
- ...format !== void 0 ? { format } : {},
17014
- ...textureFormat !== void 0 ? { textureFormat } : {},
17015
- // Additional fields
17016
- // Add levelSize field.
17017
- hasAlpha
17018
- };
17019
- }
17020
- function parseKTX2File(KTX2File, data, options) {
17021
- const ktx2File = new KTX2File(new Uint8Array(data));
17022
- try {
17023
- if (!ktx2File.startTranscoding()) {
17024
- throw new Error("failed to start KTX2 transcoding");
17025
- }
17026
- const levelsCount = ktx2File.getLevels();
17027
- const levels = [];
17028
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
17029
- levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
17030
- }
17031
- return [levels];
17032
- } finally {
17033
- ktx2File.close();
17034
- ktx2File.delete();
17035
- }
17036
- }
17037
- function transcodeKTX2Image(ktx2File, levelIndex, options) {
17038
- const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
17039
- const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
17040
- const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
17041
- const decodedData = new Uint8Array(decodedSize);
17042
- if (!ktx2File.transcodeImage(
17043
- decodedData,
17044
- levelIndex,
17045
- 0,
17046
- 0,
17047
- basisFormat,
17048
- 0,
17049
- -1,
17050
- -1
17051
- /* channel1 */
17052
- )) {
17053
- throw new Error("Failed to transcode KTX2 image");
17054
- }
17055
- return {
17056
- // standard loaders.gl image category payload
17057
- shape: "texture-level",
17058
- width,
17059
- height,
17060
- data: decodedData,
17061
- compressed,
17062
- ...format !== void 0 ? { format } : {},
17063
- ...textureFormat !== void 0 ? { textureFormat } : {},
17064
- // Additional fields
17065
- levelSize: decodedSize,
17066
- hasAlpha: alphaFlag
17067
- };
17068
- }
17069
- function getBasisOptions(options, hasAlpha) {
17070
- let format = options.basis?.format || "auto";
17071
- if (format === "auto") {
17072
- format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
17073
- }
17074
- if (typeof format === "object") {
17075
- format = hasAlpha ? format.alpha : format.noAlpha;
17076
- }
17077
- const normalizedFormat = format.toLowerCase();
17078
- const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
17079
- if (!basisOutputOptions) {
17080
- throw new Error(`Unknown Basis format ${format}`);
17081
- }
17082
- return basisOutputOptions;
17083
- }
17084
- function selectSupportedBasisFormat(supportedTextureFormats = detectSupportedTextureFormats()) {
17085
- const textureFormats2 = new Set(supportedTextureFormats);
17086
- if (hasSupportedTextureFormat(textureFormats2, ["astc-4x4-unorm", "astc-4x4-unorm-srgb"])) {
17087
- return "astc-4x4";
17088
- } else if (hasSupportedTextureFormat(textureFormats2, ["bc7-rgba-unorm", "bc7-rgba-unorm-srgb"])) {
17089
- return {
17090
- alpha: "bc7-m5",
17091
- noAlpha: "bc7-m6-opaque-only"
17092
- };
17093
- } else if (hasSupportedTextureFormat(textureFormats2, [
17094
- "bc1-rgb-unorm-webgl",
17095
- "bc1-rgb-unorm-srgb-webgl",
17096
- "bc1-rgba-unorm",
17097
- "bc1-rgba-unorm-srgb",
17098
- "bc2-rgba-unorm",
17099
- "bc2-rgba-unorm-srgb",
17100
- "bc3-rgba-unorm",
17101
- "bc3-rgba-unorm-srgb"
17102
- ])) {
17103
- return {
17104
- alpha: "bc3",
17105
- noAlpha: "bc1"
17106
- };
17107
- } else if (hasSupportedTextureFormat(textureFormats2, [
17108
- "pvrtc-rgb4unorm-webgl",
17109
- "pvrtc-rgba4unorm-webgl",
17110
- "pvrtc-rgb2unorm-webgl",
17111
- "pvrtc-rgba2unorm-webgl"
17112
- ])) {
17113
- return {
17114
- alpha: "pvrtc1-4-rgba",
17115
- noAlpha: "pvrtc1-4-rgb"
17116
- };
17117
- } else if (hasSupportedTextureFormat(textureFormats2, [
17118
- "etc2-rgb8unorm",
17119
- "etc2-rgb8unorm-srgb",
17120
- "etc2-rgb8a1unorm",
17121
- "etc2-rgb8a1unorm-srgb",
17122
- "etc2-rgba8unorm",
17123
- "etc2-rgba8unorm-srgb",
17124
- "eac-r11unorm",
17125
- "eac-r11snorm",
17126
- "eac-rg11unorm",
17127
- "eac-rg11snorm"
17128
- ])) {
17129
- return "etc2";
17130
- } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
17131
- return "etc1";
17132
- } else if (hasSupportedTextureFormat(textureFormats2, [
17133
- "atc-rgb-unorm-webgl",
17134
- "atc-rgba-unorm-webgl",
17135
- "atc-rgbai-unorm-webgl"
17136
- ])) {
17137
- return {
17138
- alpha: "atc-rgba-interpolated-alpha",
17139
- noAlpha: "atc-rgb"
17140
- };
17141
- }
17142
- return "rgb565";
17143
- }
17144
- function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
17145
- return candidateTextureFormats.some((textureFormat) => supportedTextureFormats.has(textureFormat));
17146
- }
17147
-
17148
- // ../../node_modules/@loaders.gl/textures/dist/basis-loader.js
17149
- var BasisWorkerLoader = {
17150
- dataType: null,
17151
- batchType: null,
17152
- name: "Basis",
17153
- id: "basis",
17154
- module: "textures",
17155
- version: VERSION8,
17156
- worker: true,
17157
- extensions: ["basis", "ktx2"],
17158
- mimeTypes: ["application/octet-stream", "image/ktx2"],
17159
- tests: ["sB"],
17160
- binary: true,
17161
- options: {
17162
- basis: {
17163
- format: "auto",
17164
- containerFormat: "auto",
17165
- module: "transcoder"
17166
- }
17167
- }
17168
- };
17169
- var BasisLoader = {
17170
- ...BasisWorkerLoader,
17171
- parse: parseBasis
17172
- };
17173
-
17174
16589
  // ../../node_modules/@luma.gl/gltf/dist/parsers/parse-pbr-material.js
17175
16590
  var import_core21 = __toESM(require_core3(), 1);
17176
16591
 
@@ -24065,7 +23480,7 @@ void main(void) {
24065
23480
  };
24066
23481
 
24067
23482
  // ../../node_modules/@loaders.gl/3d-tiles/dist/lib/utils/version.js
24068
- var VERSION9 = true ? "4.4.1" : "latest";
23483
+ var VERSION8 = true ? "4.4.3" : "latest";
24069
23484
 
24070
23485
  // ../../node_modules/@loaders.gl/3d-tiles/dist/lib/constants.js
24071
23486
  var TILE3D_TYPE = {
@@ -24184,7 +23599,7 @@ void main(void) {
24184
23599
  }
24185
23600
 
24186
23601
  // ../../node_modules/@loaders.gl/draco/dist/lib/utils/version.js
24187
- var VERSION10 = true ? "4.4.1" : "latest";
23602
+ var VERSION9 = true ? "4.4.3" : "latest";
24188
23603
 
24189
23604
  // ../../node_modules/@loaders.gl/schema-utils/dist/lib/schema/data-type.js
24190
23605
  function getDataTypeFromTypedArray(array) {
@@ -24755,7 +24170,7 @@ void main(void) {
24755
24170
  id: "draco",
24756
24171
  module: "draco",
24757
24172
  // shapes: ['mesh'],
24758
- version: VERSION10,
24173
+ version: VERSION9,
24759
24174
  worker: true,
24760
24175
  extensions: ["drc"],
24761
24176
  mimeTypes: ["application/octet-stream"],
@@ -26195,631 +25610,1032 @@ void main(void) {
26195
25610
  getRequiredExtensions() {
26196
25611
  return this.json.extensionsRequired || [];
26197
25612
  }
26198
- getUsedExtensions() {
26199
- return this.json.extensionsUsed || [];
25613
+ getUsedExtensions() {
25614
+ return this.json.extensionsUsed || [];
25615
+ }
25616
+ getRemovedExtensions() {
25617
+ return this.json.extensionsRemoved || [];
25618
+ }
25619
+ getObjectExtension(object, extensionName) {
25620
+ const extensions = object.extensions || {};
25621
+ return extensions[extensionName];
25622
+ }
25623
+ getScene(index) {
25624
+ return this.getObject("scenes", index);
25625
+ }
25626
+ getNode(index) {
25627
+ return this.getObject("nodes", index);
25628
+ }
25629
+ getSkin(index) {
25630
+ return this.getObject("skins", index);
25631
+ }
25632
+ getMesh(index) {
25633
+ return this.getObject("meshes", index);
25634
+ }
25635
+ getMaterial(index) {
25636
+ return this.getObject("materials", index);
25637
+ }
25638
+ getAccessor(index) {
25639
+ return this.getObject("accessors", index);
25640
+ }
25641
+ // getCamera(index: number): object | null {
25642
+ // return null; // TODO: fix thi: object as null;
25643
+ // }
25644
+ getTexture(index) {
25645
+ return this.getObject("textures", index);
25646
+ }
25647
+ getSampler(index) {
25648
+ return this.getObject("samplers", index);
25649
+ }
25650
+ getImage(index) {
25651
+ return this.getObject("images", index);
25652
+ }
25653
+ getBufferView(index) {
25654
+ return this.getObject("bufferViews", index);
25655
+ }
25656
+ getBuffer(index) {
25657
+ return this.getObject("buffers", index);
25658
+ }
25659
+ getObject(array, index) {
25660
+ if (typeof index === "object") {
25661
+ return index;
25662
+ }
25663
+ const object = this.json[array] && this.json[array][index];
25664
+ if (!object) {
25665
+ throw new Error(`glTF file error: Could not find ${array}[${index}]`);
25666
+ }
25667
+ return object;
25668
+ }
25669
+ /**
25670
+ * Accepts buffer view index or buffer view object
25671
+ * @returns a `Uint8Array`
25672
+ */
25673
+ getTypedArrayForBufferView(bufferView) {
25674
+ bufferView = this.getBufferView(bufferView);
25675
+ const bufferIndex = bufferView.buffer;
25676
+ const binChunk = this.gltf.buffers[bufferIndex];
25677
+ assert8(binChunk);
25678
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
25679
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
25680
+ }
25681
+ /** Accepts accessor index or accessor object
25682
+ * @returns a typed array with type that matches the types
25683
+ */
25684
+ getTypedArrayForAccessor(accessor) {
25685
+ const gltfAccessor = this.getAccessor(accessor);
25686
+ return getTypedArrayForAccessor(this.gltf.json, this.gltf.buffers, gltfAccessor);
25687
+ }
25688
+ /** accepts accessor index or accessor object
25689
+ * returns a `Uint8Array`
25690
+ */
25691
+ getTypedArrayForImageData(image) {
25692
+ image = this.getAccessor(image);
25693
+ const bufferView = this.getBufferView(image.bufferView);
25694
+ const buffer = this.getBuffer(bufferView.buffer);
25695
+ const arrayBuffer = buffer.data;
25696
+ const byteOffset = bufferView.byteOffset || 0;
25697
+ return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
25698
+ }
25699
+ // MODIFERS
25700
+ /**
25701
+ * Add an extra application-defined key to the top-level data structure
25702
+ */
25703
+ addApplicationData(key, data) {
25704
+ this.json[key] = data;
25705
+ return this;
25706
+ }
25707
+ /**
25708
+ * `extras` - Standard GLTF field for storing application specific data
25709
+ */
25710
+ addExtraData(key, data) {
25711
+ this.json.extras = this.json.extras || {};
25712
+ this.json.extras[key] = data;
25713
+ return this;
25714
+ }
25715
+ addObjectExtension(object, extensionName, data) {
25716
+ object.extensions = object.extensions || {};
25717
+ object.extensions[extensionName] = data;
25718
+ this.registerUsedExtension(extensionName);
25719
+ return this;
25720
+ }
25721
+ setObjectExtension(object, extensionName, data) {
25722
+ const extensions = object.extensions || {};
25723
+ extensions[extensionName] = data;
25724
+ }
25725
+ removeObjectExtension(object, extensionName) {
25726
+ const extensions = object?.extensions || {};
25727
+ if (extensions[extensionName]) {
25728
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
25729
+ const extensionsRemoved = this.json.extensionsRemoved;
25730
+ if (!extensionsRemoved.includes(extensionName)) {
25731
+ extensionsRemoved.push(extensionName);
25732
+ }
25733
+ }
25734
+ delete extensions[extensionName];
25735
+ }
25736
+ /**
25737
+ * Add to standard GLTF top level extension object, mark as used
25738
+ */
25739
+ addExtension(extensionName, extensionData = {}) {
25740
+ assert8(extensionData);
25741
+ this.json.extensions = this.json.extensions || {};
25742
+ this.json.extensions[extensionName] = extensionData;
25743
+ this.registerUsedExtension(extensionName);
25744
+ return extensionData;
25745
+ }
25746
+ /**
25747
+ * Standard GLTF top level extension object, mark as used and required
25748
+ */
25749
+ addRequiredExtension(extensionName, extensionData = {}) {
25750
+ assert8(extensionData);
25751
+ this.addExtension(extensionName, extensionData);
25752
+ this.registerRequiredExtension(extensionName);
25753
+ return extensionData;
25754
+ }
25755
+ /**
25756
+ * Add extensionName to list of used extensions
25757
+ */
25758
+ registerUsedExtension(extensionName) {
25759
+ this.json.extensionsUsed = this.json.extensionsUsed || [];
25760
+ if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) {
25761
+ this.json.extensionsUsed.push(extensionName);
25762
+ }
26200
25763
  }
26201
- getRemovedExtensions() {
26202
- return this.json.extensionsRemoved || [];
25764
+ /**
25765
+ * Add extensionName to list of required extensions
25766
+ */
25767
+ registerRequiredExtension(extensionName) {
25768
+ this.registerUsedExtension(extensionName);
25769
+ this.json.extensionsRequired = this.json.extensionsRequired || [];
25770
+ if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) {
25771
+ this.json.extensionsRequired.push(extensionName);
25772
+ }
26203
25773
  }
26204
- getObjectExtension(object, extensionName) {
26205
- const extensions = object.extensions || {};
26206
- return extensions[extensionName];
25774
+ /**
25775
+ * Removes an extension from the top-level list
25776
+ */
25777
+ removeExtension(extensionName) {
25778
+ if (this.json.extensions?.[extensionName]) {
25779
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
25780
+ const extensionsRemoved = this.json.extensionsRemoved;
25781
+ if (!extensionsRemoved.includes(extensionName)) {
25782
+ extensionsRemoved.push(extensionName);
25783
+ }
25784
+ }
25785
+ if (this.json.extensions) {
25786
+ delete this.json.extensions[extensionName];
25787
+ }
25788
+ if (this.json.extensionsRequired) {
25789
+ this._removeStringFromArray(this.json.extensionsRequired, extensionName);
25790
+ }
25791
+ if (this.json.extensionsUsed) {
25792
+ this._removeStringFromArray(this.json.extensionsUsed, extensionName);
25793
+ }
26207
25794
  }
26208
- getScene(index) {
26209
- return this.getObject("scenes", index);
25795
+ /**
25796
+ * Set default scene which is to be displayed at load time
25797
+ */
25798
+ setDefaultScene(sceneIndex) {
25799
+ this.json.scene = sceneIndex;
26210
25800
  }
26211
- getNode(index) {
26212
- return this.getObject("nodes", index);
25801
+ /**
25802
+ * @todo: add more properties for scene initialization:
25803
+ * name`, `extensions`, `extras`
25804
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene
25805
+ */
25806
+ addScene(scene) {
25807
+ const { nodeIndices } = scene;
25808
+ this.json.scenes = this.json.scenes || [];
25809
+ this.json.scenes.push({ nodes: nodeIndices });
25810
+ return this.json.scenes.length - 1;
26213
25811
  }
26214
- getSkin(index) {
26215
- return this.getObject("skins", index);
25812
+ /**
25813
+ * @todo: add more properties for node initialization:
25814
+ * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`
25815
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node
25816
+ */
25817
+ addNode(node) {
25818
+ const { meshIndex, matrix } = node;
25819
+ this.json.nodes = this.json.nodes || [];
25820
+ const nodeData = { mesh: meshIndex };
25821
+ if (matrix) {
25822
+ nodeData.matrix = matrix;
25823
+ }
25824
+ this.json.nodes.push(nodeData);
25825
+ return this.json.nodes.length - 1;
26216
25826
  }
26217
- getMesh(index) {
26218
- return this.getObject("meshes", index);
25827
+ /** Adds a mesh to the json part */
25828
+ addMesh(mesh) {
25829
+ const { attributes, indices, material, mode = 4 } = mesh;
25830
+ const accessors = this._addAttributes(attributes);
25831
+ const glTFMesh = {
25832
+ primitives: [
25833
+ {
25834
+ attributes: accessors,
25835
+ mode
25836
+ }
25837
+ ]
25838
+ };
25839
+ if (indices) {
25840
+ const indicesAccessor = this._addIndices(indices);
25841
+ glTFMesh.primitives[0].indices = indicesAccessor;
25842
+ }
25843
+ if (Number.isFinite(material)) {
25844
+ glTFMesh.primitives[0].material = material;
25845
+ }
25846
+ this.json.meshes = this.json.meshes || [];
25847
+ this.json.meshes.push(glTFMesh);
25848
+ return this.json.meshes.length - 1;
26219
25849
  }
26220
- getMaterial(index) {
26221
- return this.getObject("materials", index);
25850
+ addPointCloud(attributes) {
25851
+ const accessorIndices = this._addAttributes(attributes);
25852
+ const glTFMesh = {
25853
+ primitives: [
25854
+ {
25855
+ attributes: accessorIndices,
25856
+ mode: 0
25857
+ // GL.POINTS
25858
+ }
25859
+ ]
25860
+ };
25861
+ this.json.meshes = this.json.meshes || [];
25862
+ this.json.meshes.push(glTFMesh);
25863
+ return this.json.meshes.length - 1;
26222
25864
  }
26223
- getAccessor(index) {
26224
- return this.getObject("accessors", index);
25865
+ /**
25866
+ * Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference
25867
+ * Buffer will be copied into BIN chunk during "pack"
25868
+ * Currently encodes as glTF image
25869
+ * @param imageData
25870
+ * @param mimeType
25871
+ */
25872
+ addImage(imageData, mimeTypeOpt) {
25873
+ const metadata = getBinaryImageMetadata(imageData);
25874
+ const mimeType = mimeTypeOpt || metadata?.mimeType;
25875
+ const bufferViewIndex = this.addBufferView(imageData);
25876
+ const glTFImage = {
25877
+ bufferView: bufferViewIndex,
25878
+ mimeType
25879
+ };
25880
+ this.json.images = this.json.images || [];
25881
+ this.json.images.push(glTFImage);
25882
+ return this.json.images.length - 1;
26225
25883
  }
26226
- // getCamera(index: number): object | null {
26227
- // return null; // TODO: fix thi: object as null;
26228
- // }
26229
- getTexture(index) {
26230
- return this.getObject("textures", index);
25884
+ /**
25885
+ * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index
25886
+ * @param buffer
25887
+ */
25888
+ addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) {
25889
+ const byteLength = buffer.byteLength;
25890
+ assert8(Number.isFinite(byteLength));
25891
+ this.sourceBuffers = this.sourceBuffers || [];
25892
+ this.sourceBuffers.push(buffer);
25893
+ const glTFBufferView = {
25894
+ buffer: bufferIndex,
25895
+ // Write offset from the start of the binary body
25896
+ byteOffset,
25897
+ byteLength
25898
+ };
25899
+ this.byteLength += padToNBytes(byteLength, 4);
25900
+ this.json.bufferViews = this.json.bufferViews || [];
25901
+ this.json.bufferViews.push(glTFBufferView);
25902
+ return this.json.bufferViews.length - 1;
26231
25903
  }
26232
- getSampler(index) {
26233
- return this.getObject("samplers", index);
25904
+ /**
25905
+ * Adds an accessor to a bufferView
25906
+ * @param bufferViewIndex
25907
+ * @param accessor
25908
+ */
25909
+ addAccessor(bufferViewIndex, accessor) {
25910
+ const glTFAccessor = {
25911
+ bufferView: bufferViewIndex,
25912
+ // @ts-ignore
25913
+ type: getAccessorTypeFromSize(accessor.size),
25914
+ // @ts-ignore
25915
+ componentType: accessor.componentType,
25916
+ // @ts-ignore
25917
+ count: accessor.count,
25918
+ // @ts-ignore
25919
+ max: accessor.max,
25920
+ // @ts-ignore
25921
+ min: accessor.min
25922
+ };
25923
+ this.json.accessors = this.json.accessors || [];
25924
+ this.json.accessors.push(glTFAccessor);
25925
+ return this.json.accessors.length - 1;
26234
25926
  }
26235
- getImage(index) {
26236
- return this.getObject("images", index);
25927
+ /**
25928
+ * Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference
25929
+ * Buffer will be copied into BIN chunk during "pack"
25930
+ * Currently encodes buffers as glTF accessors, but this could be optimized
25931
+ * @param sourceBuffer
25932
+ * @param accessor
25933
+ */
25934
+ addBinaryBuffer(sourceBuffer, accessor = { size: 3 }) {
25935
+ const bufferViewIndex = this.addBufferView(sourceBuffer);
25936
+ let minMax = { min: accessor.min, max: accessor.max };
25937
+ if (!minMax.min || !minMax.max) {
25938
+ minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
25939
+ }
25940
+ const accessorDefaults = {
25941
+ // @ts-ignore
25942
+ size: accessor.size,
25943
+ componentType: getComponentTypeFromArray(sourceBuffer),
25944
+ // @ts-ignore
25945
+ count: Math.round(sourceBuffer.length / accessor.size),
25946
+ min: minMax.min,
25947
+ max: minMax.max
25948
+ };
25949
+ return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
26237
25950
  }
26238
- getBufferView(index) {
26239
- return this.getObject("bufferViews", index);
25951
+ /**
25952
+ * Adds a texture to the json part
25953
+ * @todo: add more properties for texture initialization
25954
+ * `sampler`, `name`, `extensions`, `extras`
25955
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture
25956
+ */
25957
+ addTexture(texture) {
25958
+ const { imageIndex } = texture;
25959
+ const glTFTexture = {
25960
+ source: imageIndex
25961
+ };
25962
+ this.json.textures = this.json.textures || [];
25963
+ this.json.textures.push(glTFTexture);
25964
+ return this.json.textures.length - 1;
26240
25965
  }
26241
- getBuffer(index) {
26242
- return this.getObject("buffers", index);
25966
+ /** Adds a material to the json part */
25967
+ addMaterial(pbrMaterialInfo) {
25968
+ this.json.materials = this.json.materials || [];
25969
+ this.json.materials.push(pbrMaterialInfo);
25970
+ return this.json.materials.length - 1;
26243
25971
  }
26244
- getObject(array, index) {
26245
- if (typeof index === "object") {
26246
- return index;
25972
+ /** Pack the binary chunk */
25973
+ createBinaryChunk() {
25974
+ const totalByteLength = this.byteLength;
25975
+ const arrayBuffer = new ArrayBuffer(totalByteLength);
25976
+ const targetArray = new Uint8Array(arrayBuffer);
25977
+ let dstByteOffset = 0;
25978
+ for (const sourceBuffer of this.sourceBuffers || []) {
25979
+ dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);
25980
+ }
25981
+ if (this.json?.buffers?.[0]) {
25982
+ this.json.buffers[0].byteLength = totalByteLength;
25983
+ } else {
25984
+ this.json.buffers = [{ byteLength: totalByteLength }];
26247
25985
  }
26248
- const object = this.json[array] && this.json[array][index];
26249
- if (!object) {
26250
- throw new Error(`glTF file error: Could not find ${array}[${index}]`);
25986
+ this.gltf.binary = arrayBuffer;
25987
+ this.sourceBuffers = [arrayBuffer];
25988
+ this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }];
25989
+ }
25990
+ // PRIVATE
25991
+ _removeStringFromArray(array, string) {
25992
+ let found = true;
25993
+ while (found) {
25994
+ const index = array.indexOf(string);
25995
+ if (index > -1) {
25996
+ array.splice(index, 1);
25997
+ } else {
25998
+ found = false;
25999
+ }
26251
26000
  }
26252
- return object;
26253
26001
  }
26254
26002
  /**
26255
- * Accepts buffer view index or buffer view object
26256
- * @returns a `Uint8Array`
26003
+ * Add attributes to buffers and create `attributes` object which is part of `mesh`
26257
26004
  */
26258
- getTypedArrayForBufferView(bufferView) {
26259
- bufferView = this.getBufferView(bufferView);
26260
- const bufferIndex = bufferView.buffer;
26261
- const binChunk = this.gltf.buffers[bufferIndex];
26262
- assert8(binChunk);
26263
- const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
26264
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
26005
+ _addAttributes(attributes = {}) {
26006
+ const result = {};
26007
+ for (const attributeKey in attributes) {
26008
+ const attributeData = attributes[attributeKey];
26009
+ const attrName = this._getGltfAttributeName(attributeKey);
26010
+ const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
26011
+ result[attrName] = accessor;
26012
+ }
26013
+ return result;
26265
26014
  }
26266
- /** Accepts accessor index or accessor object
26267
- * @returns a typed array with type that matches the types
26015
+ /**
26016
+ * Add indices to buffers
26268
26017
  */
26269
- getTypedArrayForAccessor(accessor) {
26270
- const gltfAccessor = this.getAccessor(accessor);
26271
- return getTypedArrayForAccessor(this.gltf.json, this.gltf.buffers, gltfAccessor);
26018
+ _addIndices(indices) {
26019
+ return this.addBinaryBuffer(indices, { size: 1 });
26272
26020
  }
26273
- /** accepts accessor index or accessor object
26274
- * returns a `Uint8Array`
26021
+ /**
26022
+ * Deduce gltf specific attribue name from input attribute name
26275
26023
  */
26276
- getTypedArrayForImageData(image) {
26277
- image = this.getAccessor(image);
26278
- const bufferView = this.getBufferView(image.bufferView);
26279
- const buffer = this.getBuffer(bufferView.buffer);
26280
- const arrayBuffer = buffer.data;
26281
- const byteOffset = bufferView.byteOffset || 0;
26282
- return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
26024
+ _getGltfAttributeName(attributeName) {
26025
+ switch (attributeName.toLowerCase()) {
26026
+ case "position":
26027
+ case "positions":
26028
+ case "vertices":
26029
+ return "POSITION";
26030
+ case "normal":
26031
+ case "normals":
26032
+ return "NORMAL";
26033
+ case "color":
26034
+ case "colors":
26035
+ return "COLOR_0";
26036
+ case "texcoord":
26037
+ case "texcoords":
26038
+ return "TEXCOORD_0";
26039
+ default:
26040
+ return attributeName;
26041
+ }
26283
26042
  }
26284
- // MODIFERS
26285
26043
  /**
26286
- * Add an extra application-defined key to the top-level data structure
26044
+ * Calculate `min` and `max` arrays of accessor according to spec:
26045
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor
26287
26046
  */
26288
- addApplicationData(key, data) {
26289
- this.json[key] = data;
26290
- return this;
26047
+ _getAccessorMinMax(buffer, size) {
26048
+ const result = { min: null, max: null };
26049
+ if (buffer.length < size) {
26050
+ return result;
26051
+ }
26052
+ result.min = [];
26053
+ result.max = [];
26054
+ const initValues = buffer.subarray(0, size);
26055
+ for (const value of initValues) {
26056
+ result.min.push(value);
26057
+ result.max.push(value);
26058
+ }
26059
+ for (let index = size; index < buffer.length; index += size) {
26060
+ for (let componentIndex = 0; componentIndex < size; componentIndex++) {
26061
+ result.min[0 + componentIndex] = Math.min(
26062
+ // @ts-ignore
26063
+ result.min[0 + componentIndex],
26064
+ buffer[index + componentIndex]
26065
+ );
26066
+ result.max[0 + componentIndex] = Math.max(
26067
+ // @ts-ignore
26068
+ result.max[0 + componentIndex],
26069
+ buffer[index + componentIndex]
26070
+ );
26071
+ }
26072
+ }
26073
+ return result;
26074
+ }
26075
+ };
26076
+
26077
+ // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/utils/3d-tiles-utils.js
26078
+ function emod(n) {
26079
+ return (n % 1 + 1) % 1;
26080
+ }
26081
+ var ATTRIBUTE_TYPE_TO_COMPONENTS2 = {
26082
+ SCALAR: 1,
26083
+ VEC2: 2,
26084
+ VEC3: 3,
26085
+ VEC4: 4,
26086
+ MAT2: 4,
26087
+ MAT3: 9,
26088
+ MAT4: 16,
26089
+ BOOLEAN: 1,
26090
+ STRING: 1,
26091
+ ENUM: 1
26092
+ };
26093
+ var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2 = {
26094
+ INT8: Int8Array,
26095
+ UINT8: Uint8Array,
26096
+ INT16: Int16Array,
26097
+ UINT16: Uint16Array,
26098
+ INT32: Int32Array,
26099
+ UINT32: Uint32Array,
26100
+ INT64: BigInt64Array,
26101
+ UINT64: BigUint64Array,
26102
+ FLOAT32: Float32Array,
26103
+ FLOAT64: Float64Array
26104
+ };
26105
+ var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2 = {
26106
+ INT8: 1,
26107
+ UINT8: 1,
26108
+ INT16: 2,
26109
+ UINT16: 2,
26110
+ INT32: 4,
26111
+ UINT32: 4,
26112
+ INT64: 8,
26113
+ UINT64: 8,
26114
+ FLOAT32: 4,
26115
+ FLOAT64: 8
26116
+ };
26117
+ function getArrayElementByteSize(attributeType, componentType) {
26118
+ return ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType] * ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
26119
+ }
26120
+ function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) {
26121
+ if (offsetType !== "UINT8" && offsetType !== "UINT16" && offsetType !== "UINT32" && offsetType !== "UINT64") {
26122
+ return null;
26123
+ }
26124
+ const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);
26125
+ const arrayOffsets = convertRawBufferToMetadataArray(
26126
+ arrayOffsetsBytes,
26127
+ "SCALAR",
26128
+ // offsets consist of ONE component
26129
+ offsetType,
26130
+ numberOfElements + 1
26131
+ // The number of offsets is equal to the property table `count` plus one.
26132
+ );
26133
+ if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {
26134
+ return null;
26135
+ }
26136
+ return arrayOffsets;
26137
+ }
26138
+ function convertRawBufferToMetadataArray(data, attributeType, componentType, elementCount = 1) {
26139
+ const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
26140
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2[componentType];
26141
+ const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType];
26142
+ const length8 = elementCount * numberOfComponents;
26143
+ const byteLength = length8 * size;
26144
+ let buffer = data.buffer;
26145
+ let offset = data.byteOffset;
26146
+ if (offset % size !== 0) {
26147
+ const bufferArray = new Uint8Array(buffer);
26148
+ buffer = bufferArray.slice(offset, offset + byteLength).buffer;
26149
+ offset = 0;
26150
+ }
26151
+ return new ArrayType(ensureArrayBuffer(buffer), offset, length8);
26152
+ }
26153
+ function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
26154
+ const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
26155
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
26156
+ const textureCoordinates = scenegraph.getTypedArrayForAccessor(texCoordAccessorIndex);
26157
+ const json = scenegraph.gltf.json;
26158
+ const textureIndex = textureInfo.index;
26159
+ const imageIndex = json.textures?.[textureIndex]?.source;
26160
+ if (typeof imageIndex !== "undefined") {
26161
+ const mimeType = json.images?.[imageIndex]?.mimeType;
26162
+ const parsedImage = scenegraph.gltf.images?.[imageIndex];
26163
+ if (parsedImage && typeof parsedImage.width !== "undefined") {
26164
+ const textureData = [];
26165
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
26166
+ const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels);
26167
+ textureData.push(value);
26168
+ }
26169
+ return textureData;
26170
+ }
26171
+ }
26172
+ return [];
26173
+ }
26174
+ function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
26175
+ if (!propertyData?.length) {
26176
+ return;
26177
+ }
26178
+ const featureIndices = [];
26179
+ for (const texelData of propertyData) {
26180
+ let index = featureTable.findIndex((item) => item === texelData);
26181
+ if (index === -1) {
26182
+ index = featureTable.push(texelData) - 1;
26183
+ }
26184
+ featureIndices.push(index);
26185
+ }
26186
+ const typedArray = new Uint32Array(featureIndices);
26187
+ const bufferIndex = scenegraph.gltf.buffers.push({
26188
+ arrayBuffer: typedArray.buffer,
26189
+ byteOffset: typedArray.byteOffset,
26190
+ byteLength: typedArray.byteLength
26191
+ }) - 1;
26192
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
26193
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
26194
+ size: 1,
26195
+ componentType: getComponentTypeFromArray(typedArray),
26196
+ count: typedArray.length
26197
+ });
26198
+ primitive.attributes[attributeName] = accessorIndex;
26199
+ }
26200
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) {
26201
+ const CHANNELS_MAP = {
26202
+ r: { offset: 0, shift: 0 },
26203
+ g: { offset: 1, shift: 8 },
26204
+ b: { offset: 2, shift: 16 },
26205
+ a: { offset: 3, shift: 24 }
26206
+ };
26207
+ const u2 = textureCoordinates[index];
26208
+ const v2 = textureCoordinates[index + 1];
26209
+ let components = 1;
26210
+ if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1))
26211
+ components = 4;
26212
+ const offset = coordinatesToOffset(u2, v2, parsedImage, components);
26213
+ let value = 0;
26214
+ for (const c2 of channels) {
26215
+ const map2 = typeof c2 === "number" ? Object.values(CHANNELS_MAP)[c2] : CHANNELS_MAP[c2];
26216
+ const imageOffset = offset + map2.offset;
26217
+ const imageData = getImageData(parsedImage);
26218
+ if (imageData.data.length <= imageOffset) {
26219
+ throw new Error(`${imageData.data.length} <= ${imageOffset}`);
26220
+ }
26221
+ const imageValue = imageData.data[imageOffset];
26222
+ value |= imageValue << map2.shift;
26291
26223
  }
26292
- /**
26293
- * `extras` - Standard GLTF field for storing application specific data
26294
- */
26295
- addExtraData(key, data) {
26296
- this.json.extras = this.json.extras || {};
26297
- this.json.extras[key] = data;
26298
- return this;
26224
+ return value;
26225
+ }
26226
+ function coordinatesToOffset(u2, v2, parsedImage, componentsCount = 1) {
26227
+ const w2 = parsedImage.width;
26228
+ const iX = emod(u2) * (w2 - 1);
26229
+ const indX = Math.round(iX);
26230
+ const h = parsedImage.height;
26231
+ const iY = emod(v2) * (h - 1);
26232
+ const indY = Math.round(iY);
26233
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
26234
+ const offset = (indY * w2 + indX) * components;
26235
+ return offset;
26236
+ }
26237
+ function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) {
26238
+ const attributeValueArray = [];
26239
+ for (let index = 0; index < numberOfElements; index++) {
26240
+ const arrayOffset = arrayOffsets[index];
26241
+ const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
26242
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
26243
+ break;
26244
+ }
26245
+ const typedArrayOffset = arrayOffset / valueSize;
26246
+ const elementCount = arrayByteSize / valueSize;
26247
+ attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));
26299
26248
  }
26300
- addObjectExtension(object, extensionName, data) {
26301
- object.extensions = object.extensions || {};
26302
- object.extensions[extensionName] = data;
26303
- this.registerUsedExtension(extensionName);
26304
- return this;
26249
+ return attributeValueArray;
26250
+ }
26251
+ function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
26252
+ const attributeValueArray = [];
26253
+ for (let index = 0; index < numberOfElements; index++) {
26254
+ const elementOffset = index * arrayCount;
26255
+ attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));
26305
26256
  }
26306
- setObjectExtension(object, extensionName, data) {
26307
- const extensions = object.extensions || {};
26308
- extensions[extensionName] = data;
26257
+ return attributeValueArray;
26258
+ }
26259
+ function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
26260
+ if (arrayOffsets) {
26261
+ throw new Error("Not implemented - arrayOffsets for strings is specified");
26309
26262
  }
26310
- removeObjectExtension(object, extensionName) {
26311
- const extensions = object?.extensions || {};
26312
- if (extensions[extensionName]) {
26313
- this.json.extensionsRemoved = this.json.extensionsRemoved || [];
26314
- const extensionsRemoved = this.json.extensionsRemoved;
26315
- if (!extensionsRemoved.includes(extensionName)) {
26316
- extensionsRemoved.push(extensionName);
26263
+ if (stringOffsets) {
26264
+ const stringsArray = [];
26265
+ const textDecoder = new TextDecoder("utf8");
26266
+ let stringOffset = 0;
26267
+ for (let index = 0; index < numberOfElements; index++) {
26268
+ const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
26269
+ if (stringByteSize + stringOffset <= valuesDataBytes.length) {
26270
+ const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
26271
+ const stringAttribute = textDecoder.decode(stringData);
26272
+ stringsArray.push(stringAttribute);
26273
+ stringOffset += stringByteSize;
26317
26274
  }
26318
26275
  }
26319
- delete extensions[extensionName];
26320
- }
26321
- /**
26322
- * Add to standard GLTF top level extension object, mark as used
26323
- */
26324
- addExtension(extensionName, extensionData = {}) {
26325
- assert8(extensionData);
26326
- this.json.extensions = this.json.extensions || {};
26327
- this.json.extensions[extensionName] = extensionData;
26328
- this.registerUsedExtension(extensionName);
26329
- return extensionData;
26276
+ return stringsArray;
26330
26277
  }
26331
- /**
26332
- * Standard GLTF top level extension object, mark as used and required
26333
- */
26334
- addRequiredExtension(extensionName, extensionData = {}) {
26335
- assert8(extensionData);
26336
- this.addExtension(extensionName, extensionData);
26337
- this.registerRequiredExtension(extensionName);
26338
- return extensionData;
26278
+ return [];
26279
+ }
26280
+
26281
+ // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/EXT_mesh_features.js
26282
+ var EXT_MESH_FEATURES_NAME = "EXT_mesh_features";
26283
+ var name = EXT_MESH_FEATURES_NAME;
26284
+ async function decode(gltfData, options) {
26285
+ const scenegraph = new GLTFScenegraph(gltfData);
26286
+ decodeExtMeshFeatures(scenegraph, options);
26287
+ }
26288
+ function encode(gltfData, options) {
26289
+ const scenegraph = new GLTFScenegraph(gltfData);
26290
+ encodeExtMeshFeatures(scenegraph, options);
26291
+ scenegraph.createBinaryChunk();
26292
+ return scenegraph.gltf;
26293
+ }
26294
+ function decodeExtMeshFeatures(scenegraph, options) {
26295
+ const json = scenegraph.gltf.json;
26296
+ if (!json.meshes) {
26297
+ return;
26339
26298
  }
26340
- /**
26341
- * Add extensionName to list of used extensions
26342
- */
26343
- registerUsedExtension(extensionName) {
26344
- this.json.extensionsUsed = this.json.extensionsUsed || [];
26345
- if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) {
26346
- this.json.extensionsUsed.push(extensionName);
26299
+ for (const mesh of json.meshes) {
26300
+ for (const primitive of mesh.primitives) {
26301
+ processMeshPrimitiveFeatures(scenegraph, primitive, options);
26347
26302
  }
26348
26303
  }
26349
- /**
26350
- * Add extensionName to list of required extensions
26351
- */
26352
- registerRequiredExtension(extensionName) {
26353
- this.registerUsedExtension(extensionName);
26354
- this.json.extensionsRequired = this.json.extensionsRequired || [];
26355
- if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) {
26356
- this.json.extensionsRequired.push(extensionName);
26357
- }
26304
+ }
26305
+ function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
26306
+ if (!options?.gltf?.loadBuffers) {
26307
+ return;
26358
26308
  }
26359
- /**
26360
- * Removes an extension from the top-level list
26361
- */
26362
- removeExtension(extensionName) {
26363
- if (this.json.extensions?.[extensionName]) {
26364
- this.json.extensionsRemoved = this.json.extensionsRemoved || [];
26365
- const extensionsRemoved = this.json.extensionsRemoved;
26366
- if (!extensionsRemoved.includes(extensionName)) {
26367
- extensionsRemoved.push(extensionName);
26368
- }
26309
+ const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
26310
+ const featureIds = extension?.featureIds;
26311
+ if (!featureIds) {
26312
+ return;
26313
+ }
26314
+ for (const featureId of featureIds) {
26315
+ let featureIdData;
26316
+ if (typeof featureId.attribute !== "undefined") {
26317
+ const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
26318
+ const accessorIndex = primitive.attributes[accessorKey];
26319
+ featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
26320
+ } else if (typeof featureId.texture !== "undefined" && options?.gltf?.loadImages) {
26321
+ featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
26322
+ } else {
26323
+ featureIdData = [];
26369
26324
  }
26370
- if (this.json.extensions) {
26371
- delete this.json.extensions[extensionName];
26325
+ featureId.data = featureIdData;
26326
+ }
26327
+ }
26328
+ function encodeExtMeshFeatures(scenegraph, options) {
26329
+ const meshes = scenegraph.gltf.json.meshes;
26330
+ if (!meshes) {
26331
+ return;
26332
+ }
26333
+ for (const mesh of meshes) {
26334
+ for (const primitive of mesh.primitives) {
26335
+ encodeExtMeshFeaturesForPrimitive(scenegraph, primitive);
26372
26336
  }
26373
- if (this.json.extensionsRequired) {
26374
- this._removeStringFromArray(this.json.extensionsRequired, extensionName);
26337
+ }
26338
+ }
26339
+ function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) {
26340
+ if (!primitive.extensions) {
26341
+ primitive.extensions = {};
26342
+ }
26343
+ let extension = primitive.extensions[EXT_MESH_FEATURES_NAME];
26344
+ if (!extension) {
26345
+ extension = { featureIds: [] };
26346
+ primitive.extensions[EXT_MESH_FEATURES_NAME] = extension;
26347
+ }
26348
+ const { featureIds } = extension;
26349
+ const featureId = {
26350
+ featureCount: featureIdArray.length,
26351
+ propertyTable: propertyTableIndex,
26352
+ data: featureIdArray
26353
+ };
26354
+ featureIds.push(featureId);
26355
+ scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension);
26356
+ }
26357
+ function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) {
26358
+ const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
26359
+ if (!extension) {
26360
+ return;
26361
+ }
26362
+ const featureIds = extension.featureIds;
26363
+ featureIds.forEach((featureId, elementIndex) => {
26364
+ if (featureId.data) {
26365
+ const { accessorKey, index } = createAccessorKey(primitive.attributes);
26366
+ const typedArray = new Uint32Array(featureId.data);
26367
+ featureIds[elementIndex] = {
26368
+ featureCount: typedArray.length,
26369
+ propertyTable: featureId.propertyTable,
26370
+ attribute: index
26371
+ };
26372
+ scenegraph.gltf.buffers.push({
26373
+ arrayBuffer: typedArray.buffer,
26374
+ byteOffset: typedArray.byteOffset,
26375
+ byteLength: typedArray.byteLength
26376
+ });
26377
+ const bufferViewIndex = scenegraph.addBufferView(typedArray);
26378
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
26379
+ size: 1,
26380
+ componentType: getComponentTypeFromArray(typedArray),
26381
+ count: typedArray.length
26382
+ });
26383
+ primitive.attributes[accessorKey] = accessorIndex;
26375
26384
  }
26376
- if (this.json.extensionsUsed) {
26377
- this._removeStringFromArray(this.json.extensionsUsed, extensionName);
26385
+ });
26386
+ }
26387
+ function createAccessorKey(attributes) {
26388
+ const prefix = "_FEATURE_ID_";
26389
+ const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0);
26390
+ let max4 = -1;
26391
+ for (const a2 of attrs) {
26392
+ const n = Number(a2.substring(prefix.length));
26393
+ if (n > max4) {
26394
+ max4 = n;
26378
26395
  }
26379
26396
  }
26380
- /**
26381
- * Set default scene which is to be displayed at load time
26382
- */
26383
- setDefaultScene(sceneIndex) {
26384
- this.json.scene = sceneIndex;
26397
+ max4++;
26398
+ const accessorKey = `${prefix}${max4}`;
26399
+ return { accessorKey, index: max4 };
26400
+ }
26401
+
26402
+ // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/EXT_structural_metadata.js
26403
+ var EXT_structural_metadata_exports = {};
26404
+ __export(EXT_structural_metadata_exports, {
26405
+ createExtStructuralMetadata: () => createExtStructuralMetadata,
26406
+ decode: () => decode2,
26407
+ encode: () => encode2,
26408
+ name: () => name2
26409
+ });
26410
+ var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
26411
+ var name2 = EXT_STRUCTURAL_METADATA_NAME;
26412
+ async function decode2(gltfData, options) {
26413
+ const scenegraph = new GLTFScenegraph(gltfData);
26414
+ decodeExtStructuralMetadata(scenegraph, options);
26415
+ }
26416
+ function encode2(gltfData, options) {
26417
+ const scenegraph = new GLTFScenegraph(gltfData);
26418
+ encodeExtStructuralMetadata(scenegraph, options);
26419
+ scenegraph.createBinaryChunk();
26420
+ return scenegraph.gltf;
26421
+ }
26422
+ function decodeExtStructuralMetadata(scenegraph, options) {
26423
+ if (!options.gltf?.loadBuffers) {
26424
+ return;
26385
26425
  }
26386
- /**
26387
- * @todo: add more properties for scene initialization:
26388
- * name`, `extensions`, `extras`
26389
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene
26390
- */
26391
- addScene(scene) {
26392
- const { nodeIndices } = scene;
26393
- this.json.scenes = this.json.scenes || [];
26394
- this.json.scenes.push({ nodes: nodeIndices });
26395
- return this.json.scenes.length - 1;
26426
+ const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
26427
+ if (!extension) {
26428
+ return;
26396
26429
  }
26397
- /**
26398
- * @todo: add more properties for node initialization:
26399
- * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`
26400
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node
26401
- */
26402
- addNode(node) {
26403
- const { meshIndex, matrix } = node;
26404
- this.json.nodes = this.json.nodes || [];
26405
- const nodeData = { mesh: meshIndex };
26406
- if (matrix) {
26407
- nodeData.matrix = matrix;
26408
- }
26409
- this.json.nodes.push(nodeData);
26410
- return this.json.nodes.length - 1;
26430
+ if (options.gltf?.loadImages) {
26431
+ decodePropertyTextures(scenegraph, extension);
26411
26432
  }
26412
- /** Adds a mesh to the json part */
26413
- addMesh(mesh) {
26414
- const { attributes, indices, material, mode = 4 } = mesh;
26415
- const accessors = this._addAttributes(attributes);
26416
- const glTFMesh = {
26417
- primitives: [
26418
- {
26419
- attributes: accessors,
26420
- mode
26421
- }
26422
- ]
26423
- };
26424
- if (indices) {
26425
- const indicesAccessor = this._addIndices(indices);
26426
- glTFMesh.primitives[0].indices = indicesAccessor;
26427
- }
26428
- if (Number.isFinite(material)) {
26429
- glTFMesh.primitives[0].material = material;
26433
+ decodePropertyTables(scenegraph, extension);
26434
+ }
26435
+ function decodePropertyTextures(scenegraph, extension) {
26436
+ const propertyTextures = extension.propertyTextures;
26437
+ const json = scenegraph.gltf.json;
26438
+ if (propertyTextures && json.meshes) {
26439
+ for (const mesh of json.meshes) {
26440
+ for (const primitive of mesh.primitives) {
26441
+ processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
26442
+ }
26430
26443
  }
26431
- this.json.meshes = this.json.meshes || [];
26432
- this.json.meshes.push(glTFMesh);
26433
- return this.json.meshes.length - 1;
26434
26444
  }
26435
- addPointCloud(attributes) {
26436
- const accessorIndices = this._addAttributes(attributes);
26437
- const glTFMesh = {
26438
- primitives: [
26439
- {
26440
- attributes: accessorIndices,
26441
- mode: 0
26442
- // GL.POINTS
26443
- }
26444
- ]
26445
- };
26446
- this.json.meshes = this.json.meshes || [];
26447
- this.json.meshes.push(glTFMesh);
26448
- return this.json.meshes.length - 1;
26445
+ }
26446
+ function decodePropertyTables(scenegraph, extension) {
26447
+ const schema = extension.schema;
26448
+ if (!schema) {
26449
+ return;
26449
26450
  }
26450
- /**
26451
- * Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference
26452
- * Buffer will be copied into BIN chunk during "pack"
26453
- * Currently encodes as glTF image
26454
- * @param imageData
26455
- * @param mimeType
26456
- */
26457
- addImage(imageData, mimeTypeOpt) {
26458
- const metadata = getBinaryImageMetadata(imageData);
26459
- const mimeType = mimeTypeOpt || metadata?.mimeType;
26460
- const bufferViewIndex = this.addBufferView(imageData);
26461
- const glTFImage = {
26462
- bufferView: bufferViewIndex,
26463
- mimeType
26464
- };
26465
- this.json.images = this.json.images || [];
26466
- this.json.images.push(glTFImage);
26467
- return this.json.images.length - 1;
26451
+ const schemaClasses = schema.classes;
26452
+ const propertyTables = extension.propertyTables;
26453
+ if (schemaClasses && propertyTables) {
26454
+ for (const schemaName in schemaClasses) {
26455
+ const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
26456
+ if (propertyTable) {
26457
+ processPropertyTable(scenegraph, schema, propertyTable);
26458
+ }
26459
+ }
26468
26460
  }
26469
- /**
26470
- * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index
26471
- * @param buffer
26472
- */
26473
- addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) {
26474
- const byteLength = buffer.byteLength;
26475
- assert8(Number.isFinite(byteLength));
26476
- this.sourceBuffers = this.sourceBuffers || [];
26477
- this.sourceBuffers.push(buffer);
26478
- const glTFBufferView = {
26479
- buffer: bufferIndex,
26480
- // Write offset from the start of the binary body
26481
- byteOffset,
26482
- byteLength
26483
- };
26484
- this.byteLength += padToNBytes(byteLength, 4);
26485
- this.json.bufferViews = this.json.bufferViews || [];
26486
- this.json.bufferViews.push(glTFBufferView);
26487
- return this.json.bufferViews.length - 1;
26461
+ }
26462
+ function findPropertyTableByClass(propertyTables, schemaClassName) {
26463
+ for (const propertyTable of propertyTables) {
26464
+ if (propertyTable.class === schemaClassName) {
26465
+ return propertyTable;
26466
+ }
26488
26467
  }
26489
- /**
26490
- * Adds an accessor to a bufferView
26491
- * @param bufferViewIndex
26492
- * @param accessor
26493
- */
26494
- addAccessor(bufferViewIndex, accessor) {
26495
- const glTFAccessor = {
26496
- bufferView: bufferViewIndex,
26497
- // @ts-ignore
26498
- type: getAccessorTypeFromSize(accessor.size),
26499
- // @ts-ignore
26500
- componentType: accessor.componentType,
26501
- // @ts-ignore
26502
- count: accessor.count,
26503
- // @ts-ignore
26504
- max: accessor.max,
26505
- // @ts-ignore
26506
- min: accessor.min
26507
- };
26508
- this.json.accessors = this.json.accessors || [];
26509
- this.json.accessors.push(glTFAccessor);
26510
- return this.json.accessors.length - 1;
26468
+ return null;
26469
+ }
26470
+ function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
26471
+ if (!propertyTextures) {
26472
+ return;
26511
26473
  }
26512
- /**
26513
- * Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference
26514
- * Buffer will be copied into BIN chunk during "pack"
26515
- * Currently encodes buffers as glTF accessors, but this could be optimized
26516
- * @param sourceBuffer
26517
- * @param accessor
26518
- */
26519
- addBinaryBuffer(sourceBuffer, accessor = { size: 3 }) {
26520
- const bufferViewIndex = this.addBufferView(sourceBuffer);
26521
- let minMax = { min: accessor.min, max: accessor.max };
26522
- if (!minMax.min || !minMax.max) {
26523
- minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
26524
- }
26525
- const accessorDefaults = {
26526
- // @ts-ignore
26527
- size: accessor.size,
26528
- componentType: getComponentTypeFromArray(sourceBuffer),
26529
- // @ts-ignore
26530
- count: Math.round(sourceBuffer.length / accessor.size),
26531
- min: minMax.min,
26532
- max: minMax.max
26533
- };
26534
- return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
26474
+ const primitiveExtension = primitive.extensions?.[EXT_STRUCTURAL_METADATA_NAME];
26475
+ const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;
26476
+ if (!primitivePropertyTextureIndices) {
26477
+ return;
26535
26478
  }
26536
- /**
26537
- * Adds a texture to the json part
26538
- * @todo: add more properties for texture initialization
26539
- * `sampler`, `name`, `extensions`, `extras`
26540
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture
26541
- */
26542
- addTexture(texture) {
26543
- const { imageIndex } = texture;
26544
- const glTFTexture = {
26545
- source: imageIndex
26546
- };
26547
- this.json.textures = this.json.textures || [];
26548
- this.json.textures.push(glTFTexture);
26549
- return this.json.textures.length - 1;
26479
+ for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
26480
+ const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
26481
+ processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
26550
26482
  }
26551
- /** Adds a material to the json part */
26552
- addMaterial(pbrMaterialInfo) {
26553
- this.json.materials = this.json.materials || [];
26554
- this.json.materials.push(pbrMaterialInfo);
26555
- return this.json.materials.length - 1;
26483
+ }
26484
+ function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
26485
+ if (!propertyTexture.properties) {
26486
+ return;
26556
26487
  }
26557
- /** Pack the binary chunk */
26558
- createBinaryChunk() {
26559
- const totalByteLength = this.byteLength;
26560
- const arrayBuffer = new ArrayBuffer(totalByteLength);
26561
- const targetArray = new Uint8Array(arrayBuffer);
26562
- let dstByteOffset = 0;
26563
- for (const sourceBuffer of this.sourceBuffers || []) {
26564
- dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);
26565
- }
26566
- if (this.json?.buffers?.[0]) {
26567
- this.json.buffers[0].byteLength = totalByteLength;
26568
- } else {
26569
- this.json.buffers = [{ byteLength: totalByteLength }];
26570
- }
26571
- this.gltf.binary = arrayBuffer;
26572
- this.sourceBuffers = [arrayBuffer];
26573
- this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }];
26488
+ if (!extension.dataAttributeNames) {
26489
+ extension.dataAttributeNames = [];
26574
26490
  }
26575
- // PRIVATE
26576
- _removeStringFromArray(array, string) {
26577
- let found = true;
26578
- while (found) {
26579
- const index = array.indexOf(string);
26580
- if (index > -1) {
26581
- array.splice(index, 1);
26582
- } else {
26583
- found = false;
26584
- }
26491
+ const className = propertyTexture.class;
26492
+ for (const propertyName in propertyTexture.properties) {
26493
+ const attributeName = `${className}_${propertyName}`;
26494
+ const textureInfoTopLevel = propertyTexture.properties?.[propertyName];
26495
+ if (!textureInfoTopLevel) {
26496
+ continue;
26585
26497
  }
26586
- }
26587
- /**
26588
- * Add attributes to buffers and create `attributes` object which is part of `mesh`
26589
- */
26590
- _addAttributes(attributes = {}) {
26591
- const result = {};
26592
- for (const attributeKey in attributes) {
26593
- const attributeData = attributes[attributeKey];
26594
- const attrName = this._getGltfAttributeName(attributeKey);
26595
- const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
26596
- result[attrName] = accessor;
26498
+ if (!textureInfoTopLevel.data) {
26499
+ textureInfoTopLevel.data = [];
26597
26500
  }
26598
- return result;
26501
+ const featureTextureTable = textureInfoTopLevel.data;
26502
+ const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
26503
+ if (propertyData === null) {
26504
+ continue;
26505
+ }
26506
+ primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
26507
+ textureInfoTopLevel.data = featureTextureTable;
26508
+ extension.dataAttributeNames.push(attributeName);
26599
26509
  }
26600
- /**
26601
- * Add indices to buffers
26602
- */
26603
- _addIndices(indices) {
26604
- return this.addBinaryBuffer(indices, { size: 1 });
26510
+ }
26511
+ function processPropertyTable(scenegraph, schema, propertyTable) {
26512
+ const schemaClass = schema.classes?.[propertyTable.class];
26513
+ if (!schemaClass) {
26514
+ throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
26605
26515
  }
26606
- /**
26607
- * Deduce gltf specific attribue name from input attribute name
26608
- */
26609
- _getGltfAttributeName(attributeName) {
26610
- switch (attributeName.toLowerCase()) {
26611
- case "position":
26612
- case "positions":
26613
- case "vertices":
26614
- return "POSITION";
26615
- case "normal":
26616
- case "normals":
26617
- return "NORMAL";
26618
- case "color":
26619
- case "colors":
26620
- return "COLOR_0";
26621
- case "texcoord":
26622
- case "texcoords":
26623
- return "TEXCOORD_0";
26624
- default:
26625
- return attributeName;
26516
+ const numberOfElements = propertyTable.count;
26517
+ for (const propertyName in schemaClass.properties) {
26518
+ const classProperty = schemaClass.properties[propertyName];
26519
+ const propertyTableProperty = propertyTable.properties?.[propertyName];
26520
+ if (propertyTableProperty) {
26521
+ const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
26522
+ propertyTableProperty.data = data;
26626
26523
  }
26627
26524
  }
26628
- /**
26629
- * Calculate `min` and `max` arrays of accessor according to spec:
26630
- * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor
26631
- */
26632
- _getAccessorMinMax(buffer, size) {
26633
- const result = { min: null, max: null };
26634
- if (buffer.length < size) {
26635
- return result;
26525
+ }
26526
+ function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
26527
+ let data = [];
26528
+ const valuesBufferView = propertyTableProperty.values;
26529
+ const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
26530
+ const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements);
26531
+ const stringOffsets = getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements);
26532
+ switch (classProperty.type) {
26533
+ case "SCALAR":
26534
+ case "VEC2":
26535
+ case "VEC3":
26536
+ case "VEC4":
26537
+ case "MAT2":
26538
+ case "MAT3":
26539
+ case "MAT4": {
26540
+ data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
26541
+ break;
26636
26542
  }
26637
- result.min = [];
26638
- result.max = [];
26639
- const initValues = buffer.subarray(0, size);
26640
- for (const value of initValues) {
26641
- result.min.push(value);
26642
- result.max.push(value);
26543
+ case "BOOLEAN": {
26544
+ throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
26643
26545
  }
26644
- for (let index = size; index < buffer.length; index += size) {
26645
- for (let componentIndex = 0; componentIndex < size; componentIndex++) {
26646
- result.min[0 + componentIndex] = Math.min(
26647
- // @ts-ignore
26648
- result.min[0 + componentIndex],
26649
- buffer[index + componentIndex]
26650
- );
26651
- result.max[0 + componentIndex] = Math.max(
26652
- // @ts-ignore
26653
- result.max[0 + componentIndex],
26654
- buffer[index + componentIndex]
26655
- );
26656
- }
26546
+ case "STRING": {
26547
+ data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
26548
+ break;
26657
26549
  }
26658
- return result;
26550
+ case "ENUM": {
26551
+ data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
26552
+ break;
26553
+ }
26554
+ default:
26555
+ throw new Error(`Unknown classProperty type ${classProperty.type}`);
26659
26556
  }
26660
- };
26661
-
26662
- // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/utils/3d-tiles-utils.js
26663
- function emod(n) {
26664
- return (n % 1 + 1) % 1;
26665
- }
26666
- var ATTRIBUTE_TYPE_TO_COMPONENTS2 = {
26667
- SCALAR: 1,
26668
- VEC2: 2,
26669
- VEC3: 3,
26670
- VEC4: 4,
26671
- MAT2: 4,
26672
- MAT3: 9,
26673
- MAT4: 16,
26674
- BOOLEAN: 1,
26675
- STRING: 1,
26676
- ENUM: 1
26677
- };
26678
- var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2 = {
26679
- INT8: Int8Array,
26680
- UINT8: Uint8Array,
26681
- INT16: Int16Array,
26682
- UINT16: Uint16Array,
26683
- INT32: Int32Array,
26684
- UINT32: Uint32Array,
26685
- INT64: BigInt64Array,
26686
- UINT64: BigUint64Array,
26687
- FLOAT32: Float32Array,
26688
- FLOAT64: Float64Array
26689
- };
26690
- var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2 = {
26691
- INT8: 1,
26692
- UINT8: 1,
26693
- INT16: 2,
26694
- UINT16: 2,
26695
- INT32: 4,
26696
- UINT32: 4,
26697
- INT64: 8,
26698
- UINT64: 8,
26699
- FLOAT32: 4,
26700
- FLOAT64: 8
26701
- };
26702
- function getArrayElementByteSize(attributeType, componentType) {
26703
- return ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType] * ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
26557
+ return data;
26704
26558
  }
26705
- function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) {
26706
- if (offsetType !== "UINT8" && offsetType !== "UINT16" && offsetType !== "UINT32" && offsetType !== "UINT64") {
26707
- return null;
26708
- }
26709
- const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);
26710
- const arrayOffsets = convertRawBufferToMetadataArray(
26711
- arrayOffsetsBytes,
26712
- "SCALAR",
26713
- // offsets consist of ONE component
26714
- offsetType,
26715
- numberOfElements + 1
26716
- // The number of offsets is equal to the property table `count` plus one.
26717
- );
26718
- if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {
26719
- return null;
26559
+ function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
26560
+ if (classProperty.array && // `count` is a number of array elements. May only be defined when `array` is true.
26561
+ // If `count` is NOT defined, it's a VARIABLE-length array
26562
+ typeof classProperty.count === "undefined" && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
26563
+ typeof propertyTableProperty.arrayOffsets !== "undefined") {
26564
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || "UINT32", numberOfElements);
26720
26565
  }
26721
- return arrayOffsets;
26566
+ return null;
26722
26567
  }
26723
- function convertRawBufferToMetadataArray(data, attributeType, componentType, elementCount = 1) {
26724
- const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
26725
- const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2[componentType];
26726
- const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType];
26727
- const length8 = elementCount * numberOfComponents;
26728
- const byteLength = length8 * size;
26729
- let buffer = data.buffer;
26730
- let offset = data.byteOffset;
26731
- if (offset % size !== 0) {
26732
- const bufferArray = new Uint8Array(buffer);
26733
- buffer = bufferArray.slice(offset, offset + byteLength).buffer;
26734
- offset = 0;
26568
+ function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
26569
+ if (typeof propertyTableProperty.stringOffsets !== "undefined") {
26570
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || "UINT32", numberOfElements);
26735
26571
  }
26736
- return new ArrayType(ensureArrayBuffer(buffer), offset, length8);
26572
+ return null;
26737
26573
  }
26738
- function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
26739
- const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
26740
- const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
26741
- const textureCoordinates = scenegraph.getTypedArrayForAccessor(texCoordAccessorIndex);
26742
- const json = scenegraph.gltf.json;
26743
- const textureIndex = textureInfo.index;
26744
- const imageIndex = json.textures?.[textureIndex]?.source;
26745
- if (typeof imageIndex !== "undefined") {
26746
- const mimeType = json.images?.[imageIndex]?.mimeType;
26747
- const parsedImage = scenegraph.gltf.images?.[imageIndex];
26748
- if (parsedImage && typeof parsedImage.width !== "undefined") {
26749
- const textureData = [];
26750
- for (let index = 0; index < textureCoordinates.length; index += 2) {
26751
- const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels);
26752
- textureData.push(value);
26753
- }
26754
- return textureData;
26574
+ function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
26575
+ const isArray2 = classProperty.array;
26576
+ const arrayCount = classProperty.count;
26577
+ const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
26578
+ const elementCount = valuesDataBytes.byteLength / elementSize;
26579
+ let valuesData;
26580
+ if (classProperty.componentType) {
26581
+ valuesData = convertRawBufferToMetadataArray(
26582
+ valuesDataBytes,
26583
+ classProperty.type,
26584
+ // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
26585
+ classProperty.componentType,
26586
+ elementCount
26587
+ );
26588
+ } else {
26589
+ valuesData = valuesDataBytes;
26590
+ }
26591
+ if (isArray2) {
26592
+ if (arrayOffsets) {
26593
+ return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
26594
+ }
26595
+ if (arrayCount) {
26596
+ return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
26755
26597
  }
26598
+ return [];
26756
26599
  }
26757
- return [];
26600
+ return valuesData;
26758
26601
  }
26759
- function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
26760
- if (!propertyData?.length) {
26761
- return;
26602
+ function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
26603
+ const enumType = classProperty.enumType;
26604
+ if (!enumType) {
26605
+ throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM");
26606
+ }
26607
+ const enumEntry = schema.enums?.[enumType];
26608
+ if (!enumEntry) {
26609
+ throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`);
26610
+ }
26611
+ const enumValueType = enumEntry.valueType || "UINT16";
26612
+ const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
26613
+ const elementCount = valuesDataBytes.byteLength / elementSize;
26614
+ let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount);
26615
+ if (!valuesData) {
26616
+ valuesData = valuesDataBytes;
26762
26617
  }
26763
- const featureIndices = [];
26764
- for (const texelData of propertyData) {
26765
- let index = featureTable.findIndex((item) => item === texelData);
26766
- if (index === -1) {
26767
- index = featureTable.push(texelData) - 1;
26618
+ if (classProperty.array) {
26619
+ if (arrayOffsets) {
26620
+ return parseVariableLengthArrayENUM({
26621
+ valuesData,
26622
+ numberOfElements,
26623
+ arrayOffsets,
26624
+ valuesDataBytesLength: valuesDataBytes.length,
26625
+ elementSize,
26626
+ enumEntry
26627
+ });
26768
26628
  }
26769
- featureIndices.push(index);
26770
- }
26771
- const typedArray = new Uint32Array(featureIndices);
26772
- const bufferIndex = scenegraph.gltf.buffers.push({
26773
- arrayBuffer: typedArray.buffer,
26774
- byteOffset: typedArray.byteOffset,
26775
- byteLength: typedArray.byteLength
26776
- }) - 1;
26777
- const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
26778
- const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
26779
- size: 1,
26780
- componentType: getComponentTypeFromArray(typedArray),
26781
- count: typedArray.length
26782
- });
26783
- primitive.attributes[attributeName] = accessorIndex;
26784
- }
26785
- function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) {
26786
- const CHANNELS_MAP = {
26787
- r: { offset: 0, shift: 0 },
26788
- g: { offset: 1, shift: 8 },
26789
- b: { offset: 2, shift: 16 },
26790
- a: { offset: 3, shift: 24 }
26791
- };
26792
- const u2 = textureCoordinates[index];
26793
- const v2 = textureCoordinates[index + 1];
26794
- let components = 1;
26795
- if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1))
26796
- components = 4;
26797
- const offset = coordinatesToOffset(u2, v2, parsedImage, components);
26798
- let value = 0;
26799
- for (const c2 of channels) {
26800
- const map2 = typeof c2 === "number" ? Object.values(CHANNELS_MAP)[c2] : CHANNELS_MAP[c2];
26801
- const imageOffset = offset + map2.offset;
26802
- const imageData = getImageData(parsedImage);
26803
- if (imageData.data.length <= imageOffset) {
26804
- throw new Error(`${imageData.data.length} <= ${imageOffset}`);
26629
+ const arrayCount = classProperty.count;
26630
+ if (arrayCount) {
26631
+ return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
26805
26632
  }
26806
- const imageValue = imageData.data[imageOffset];
26807
- value |= imageValue << map2.shift;
26633
+ return [];
26808
26634
  }
26809
- return value;
26810
- }
26811
- function coordinatesToOffset(u2, v2, parsedImage, componentsCount = 1) {
26812
- const w2 = parsedImage.width;
26813
- const iX = emod(u2) * (w2 - 1);
26814
- const indX = Math.round(iX);
26815
- const h = parsedImage.height;
26816
- const iY = emod(v2) * (h - 1);
26817
- const indY = Math.round(iY);
26818
- const components = parsedImage.components ? parsedImage.components : componentsCount;
26819
- const offset = (indY * w2 + indX) * components;
26820
- return offset;
26635
+ return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);
26821
26636
  }
26822
- function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) {
26637
+ function parseVariableLengthArrayENUM(params) {
26638
+ const { valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry } = params;
26823
26639
  const attributeValueArray = [];
26824
26640
  for (let index = 0; index < numberOfElements; index++) {
26825
26641
  const arrayOffset = arrayOffsets[index];
@@ -26827,273 +26643,275 @@ void main(void) {
26827
26643
  if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
26828
26644
  break;
26829
26645
  }
26830
- const typedArrayOffset = arrayOffset / valueSize;
26831
- const elementCount = arrayByteSize / valueSize;
26832
- attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));
26646
+ const typedArrayOffset = arrayOffset / elementSize;
26647
+ const elementCount = arrayByteSize / elementSize;
26648
+ const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
26649
+ attributeValueArray.push(array);
26833
26650
  }
26834
26651
  return attributeValueArray;
26835
26652
  }
26836
- function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
26653
+ function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
26837
26654
  const attributeValueArray = [];
26838
26655
  for (let index = 0; index < numberOfElements; index++) {
26839
- const elementOffset = index * arrayCount;
26840
- attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));
26656
+ const elementOffset = arrayCount * index;
26657
+ const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);
26658
+ attributeValueArray.push(array);
26841
26659
  }
26842
26660
  return attributeValueArray;
26843
26661
  }
26844
- function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
26845
- if (arrayOffsets) {
26846
- throw new Error("Not implemented - arrayOffsets for strings is specified");
26847
- }
26848
- if (stringOffsets) {
26849
- const stringsArray = [];
26850
- const textDecoder = new TextDecoder("utf8");
26851
- let stringOffset = 0;
26852
- for (let index = 0; index < numberOfElements; index++) {
26853
- const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
26854
- if (stringByteSize + stringOffset <= valuesDataBytes.length) {
26855
- const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
26856
- const stringAttribute = textDecoder.decode(stringData);
26857
- stringsArray.push(stringAttribute);
26858
- stringOffset += stringByteSize;
26662
+ function getEnumsArray(valuesData, offset, count, enumEntry) {
26663
+ const array = [];
26664
+ for (let i = 0; i < count; i++) {
26665
+ if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {
26666
+ array.push("");
26667
+ } else {
26668
+ const value = valuesData[offset + i];
26669
+ const enumObject = getEnumByValue(enumEntry, value);
26670
+ if (enumObject) {
26671
+ array.push(enumObject.name);
26672
+ } else {
26673
+ array.push("");
26859
26674
  }
26860
26675
  }
26861
- return stringsArray;
26862
26676
  }
26863
- return [];
26864
- }
26865
-
26866
- // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/EXT_mesh_features.js
26867
- var EXT_MESH_FEATURES_NAME = "EXT_mesh_features";
26868
- var name = EXT_MESH_FEATURES_NAME;
26869
- async function decode(gltfData, options) {
26870
- const scenegraph = new GLTFScenegraph(gltfData);
26871
- decodeExtMeshFeatures(scenegraph, options);
26677
+ return array;
26872
26678
  }
26873
- function encode(gltfData, options) {
26874
- const scenegraph = new GLTFScenegraph(gltfData);
26875
- encodeExtMeshFeatures(scenegraph, options);
26876
- scenegraph.createBinaryChunk();
26877
- return scenegraph.gltf;
26679
+ function getEnumByValue(enumEntry, value) {
26680
+ for (const enumValue of enumEntry.values) {
26681
+ if (enumValue.value === value) {
26682
+ return enumValue;
26683
+ }
26684
+ }
26685
+ return null;
26878
26686
  }
26879
- function decodeExtMeshFeatures(scenegraph, options) {
26880
- const json = scenegraph.gltf.json;
26881
- if (!json.meshes) {
26687
+ var SCHEMA_CLASS_ID_DEFAULT = "schemaClassId";
26688
+ function encodeExtStructuralMetadata(scenegraph, options) {
26689
+ const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
26690
+ if (!extension) {
26882
26691
  return;
26883
26692
  }
26884
- for (const mesh of json.meshes) {
26885
- for (const primitive of mesh.primitives) {
26886
- processMeshPrimitiveFeatures(scenegraph, primitive, options);
26693
+ if (extension.propertyTables) {
26694
+ for (const table of extension.propertyTables) {
26695
+ const classId = table.class;
26696
+ const schemaClass = extension.schema?.classes?.[classId];
26697
+ if (table.properties && schemaClass) {
26698
+ encodeProperties(table, schemaClass, scenegraph);
26699
+ }
26887
26700
  }
26888
26701
  }
26889
26702
  }
26890
- function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
26891
- if (!options?.gltf?.loadBuffers) {
26892
- return;
26703
+ function encodeProperties(table, schemaClass, scenegraph) {
26704
+ for (const propertyName in table.properties) {
26705
+ const data = table.properties[propertyName].data;
26706
+ if (data) {
26707
+ const classProperty = schemaClass.properties[propertyName];
26708
+ if (classProperty) {
26709
+ const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph);
26710
+ table.properties[propertyName] = tableProperty;
26711
+ }
26712
+ }
26893
26713
  }
26894
- const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
26895
- const featureIds = extension?.featureIds;
26896
- if (!featureIds) {
26897
- return;
26714
+ }
26715
+ function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) {
26716
+ let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
26717
+ if (!extension) {
26718
+ extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME);
26898
26719
  }
26899
- for (const featureId of featureIds) {
26900
- let featureIdData;
26901
- if (typeof featureId.attribute !== "undefined") {
26902
- const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
26903
- const accessorIndex = primitive.attributes[accessorKey];
26904
- featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
26905
- } else if (typeof featureId.texture !== "undefined" && options?.gltf?.loadImages) {
26906
- featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
26907
- } else {
26908
- featureIdData = [];
26909
- }
26910
- featureId.data = featureIdData;
26720
+ extension.schema = createSchema(propertyAttributes, classId, extension.schema);
26721
+ const table = createPropertyTable(propertyAttributes, classId, extension.schema);
26722
+ if (!extension.propertyTables) {
26723
+ extension.propertyTables = [];
26911
26724
  }
26725
+ return extension.propertyTables.push(table) - 1;
26912
26726
  }
26913
- function encodeExtMeshFeatures(scenegraph, options) {
26914
- const meshes = scenegraph.gltf.json.meshes;
26915
- if (!meshes) {
26916
- return;
26727
+ function createSchema(propertyAttributes, classId, schemaToUpdate) {
26728
+ const schema = schemaToUpdate ?? {
26729
+ id: "schema_id"
26730
+ };
26731
+ const schemaClass = {
26732
+ properties: {}
26733
+ };
26734
+ for (const attribute of propertyAttributes) {
26735
+ const classProperty = {
26736
+ type: attribute.elementType,
26737
+ componentType: attribute.componentType
26738
+ };
26739
+ schemaClass.properties[attribute.name] = classProperty;
26917
26740
  }
26918
- for (const mesh of meshes) {
26919
- for (const primitive of mesh.primitives) {
26920
- encodeExtMeshFeaturesForPrimitive(scenegraph, primitive);
26741
+ schema.classes = {};
26742
+ schema.classes[classId] = schemaClass;
26743
+ return schema;
26744
+ }
26745
+ function createPropertyTable(propertyAttributes, classId, schema) {
26746
+ const table = {
26747
+ class: classId,
26748
+ count: 0
26749
+ };
26750
+ let count = 0;
26751
+ const schemaClass = schema.classes?.[classId];
26752
+ for (const attribute of propertyAttributes) {
26753
+ if (count === 0) {
26754
+ count = attribute.values.length;
26755
+ }
26756
+ if (count !== attribute.values.length && attribute.values.length) {
26757
+ throw new Error("Illegal values in attributes");
26758
+ }
26759
+ const classProperty = schemaClass?.properties[attribute.name];
26760
+ if (classProperty) {
26761
+ if (!table.properties) {
26762
+ table.properties = {};
26763
+ }
26764
+ table.properties[attribute.name] = { values: 0, data: attribute.values };
26921
26765
  }
26922
26766
  }
26767
+ table.count = count;
26768
+ return table;
26769
+ }
26770
+ function createPropertyTableProperty(values, classProperty, scenegraph) {
26771
+ const prop = { values: 0 };
26772
+ if (classProperty.type === "STRING") {
26773
+ const { stringData, stringOffsets } = createPropertyDataString(values);
26774
+ prop.stringOffsets = createBufferView(stringOffsets, scenegraph);
26775
+ prop.values = createBufferView(stringData, scenegraph);
26776
+ } else if (classProperty.type === "SCALAR" && classProperty.componentType) {
26777
+ const data = createPropertyDataScalar(values, classProperty.componentType);
26778
+ prop.values = createBufferView(data, scenegraph);
26779
+ }
26780
+ return prop;
26923
26781
  }
26924
- function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) {
26925
- if (!primitive.extensions) {
26926
- primitive.extensions = {};
26782
+ var COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = {
26783
+ INT8: Int8Array,
26784
+ UINT8: Uint8Array,
26785
+ INT16: Int16Array,
26786
+ UINT16: Uint16Array,
26787
+ INT32: Int32Array,
26788
+ UINT32: Uint32Array,
26789
+ INT64: Int32Array,
26790
+ UINT64: Uint32Array,
26791
+ FLOAT32: Float32Array,
26792
+ FLOAT64: Float64Array
26793
+ };
26794
+ function createPropertyDataScalar(array, componentType) {
26795
+ const numberArray = [];
26796
+ for (const value of array) {
26797
+ numberArray.push(Number(value));
26927
26798
  }
26928
- let extension = primitive.extensions[EXT_MESH_FEATURES_NAME];
26929
- if (!extension) {
26930
- extension = { featureIds: [] };
26931
- primitive.extensions[EXT_MESH_FEATURES_NAME] = extension;
26799
+ const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType];
26800
+ if (!Construct) {
26801
+ throw new Error("Illegal component type");
26932
26802
  }
26933
- const { featureIds } = extension;
26934
- const featureId = {
26935
- featureCount: featureIdArray.length,
26936
- propertyTable: propertyTableIndex,
26937
- data: featureIdArray
26938
- };
26939
- featureIds.push(featureId);
26940
- scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension);
26803
+ return new Construct(numberArray);
26941
26804
  }
26942
- function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) {
26943
- const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
26944
- if (!extension) {
26945
- return;
26805
+ function createPropertyDataString(strings) {
26806
+ const utf8Encode = new TextEncoder();
26807
+ const arr = [];
26808
+ let len5 = 0;
26809
+ for (const str7 of strings) {
26810
+ const uint8Array = utf8Encode.encode(str7);
26811
+ len5 += uint8Array.length;
26812
+ arr.push(uint8Array);
26946
26813
  }
26947
- const featureIds = extension.featureIds;
26948
- featureIds.forEach((featureId, elementIndex) => {
26949
- if (featureId.data) {
26950
- const { accessorKey, index } = createAccessorKey(primitive.attributes);
26951
- const typedArray = new Uint32Array(featureId.data);
26952
- featureIds[elementIndex] = {
26953
- featureCount: typedArray.length,
26954
- propertyTable: featureId.propertyTable,
26955
- attribute: index
26956
- };
26957
- scenegraph.gltf.buffers.push({
26958
- arrayBuffer: typedArray.buffer,
26959
- byteOffset: typedArray.byteOffset,
26960
- byteLength: typedArray.byteLength
26961
- });
26962
- const bufferViewIndex = scenegraph.addBufferView(typedArray);
26963
- const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
26964
- size: 1,
26965
- componentType: getComponentTypeFromArray(typedArray),
26966
- count: typedArray.length
26967
- });
26968
- primitive.attributes[accessorKey] = accessorIndex;
26969
- }
26970
- });
26971
- }
26972
- function createAccessorKey(attributes) {
26973
- const prefix = "_FEATURE_ID_";
26974
- const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0);
26975
- let max4 = -1;
26976
- for (const a2 of attrs) {
26977
- const n = Number(a2.substring(prefix.length));
26978
- if (n > max4) {
26979
- max4 = n;
26980
- }
26814
+ const strArray = new Uint8Array(len5);
26815
+ const strOffsets = [];
26816
+ let offset = 0;
26817
+ for (const str7 of arr) {
26818
+ strArray.set(str7, offset);
26819
+ strOffsets.push(offset);
26820
+ offset += str7.length;
26981
26821
  }
26982
- max4++;
26983
- const accessorKey = `${prefix}${max4}`;
26984
- return { accessorKey, index: max4 };
26822
+ strOffsets.push(offset);
26823
+ const stringOffsetsTypedArray = new Uint32Array(strOffsets);
26824
+ return { stringData: strArray, stringOffsets: stringOffsetsTypedArray };
26825
+ }
26826
+ function createBufferView(typedArray, scenegraph) {
26827
+ scenegraph.gltf.buffers.push({
26828
+ arrayBuffer: ensureArrayBuffer(typedArray.buffer),
26829
+ byteOffset: typedArray.byteOffset,
26830
+ byteLength: typedArray.byteLength
26831
+ });
26832
+ return scenegraph.addBufferView(typedArray);
26985
26833
  }
26986
26834
 
26987
- // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/EXT_structural_metadata.js
26988
- var EXT_structural_metadata_exports = {};
26989
- __export(EXT_structural_metadata_exports, {
26990
- createExtStructuralMetadata: () => createExtStructuralMetadata,
26991
- decode: () => decode2,
26992
- encode: () => encode2,
26993
- name: () => name2
26835
+ // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/deprecated/EXT_feature_metadata.js
26836
+ var EXT_feature_metadata_exports = {};
26837
+ __export(EXT_feature_metadata_exports, {
26838
+ decode: () => decode3,
26839
+ name: () => name3
26994
26840
  });
26995
- var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
26996
- var name2 = EXT_STRUCTURAL_METADATA_NAME;
26997
- async function decode2(gltfData, options) {
26998
- const scenegraph = new GLTFScenegraph(gltfData);
26999
- decodeExtStructuralMetadata(scenegraph, options);
27000
- }
27001
- function encode2(gltfData, options) {
26841
+ var EXT_FEATURE_METADATA_NAME = "EXT_feature_metadata";
26842
+ var name3 = EXT_FEATURE_METADATA_NAME;
26843
+ async function decode3(gltfData, options) {
27002
26844
  const scenegraph = new GLTFScenegraph(gltfData);
27003
- encodeExtStructuralMetadata(scenegraph, options);
27004
- scenegraph.createBinaryChunk();
27005
- return scenegraph.gltf;
26845
+ decodeExtFeatureMetadata(scenegraph, options);
27006
26846
  }
27007
- function decodeExtStructuralMetadata(scenegraph, options) {
26847
+ function decodeExtFeatureMetadata(scenegraph, options) {
27008
26848
  if (!options.gltf?.loadBuffers) {
27009
26849
  return;
27010
26850
  }
27011
- const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
26851
+ const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
27012
26852
  if (!extension) {
27013
26853
  return;
27014
26854
  }
27015
26855
  if (options.gltf?.loadImages) {
27016
- decodePropertyTextures(scenegraph, extension);
26856
+ decodePropertyTextures2(scenegraph, extension);
27017
26857
  }
27018
- decodePropertyTables(scenegraph, extension);
26858
+ decodePropertyTables2(scenegraph, extension);
27019
26859
  }
27020
- function decodePropertyTextures(scenegraph, extension) {
27021
- const propertyTextures = extension.propertyTextures;
27022
- const json = scenegraph.gltf.json;
27023
- if (propertyTextures && json.meshes) {
27024
- for (const mesh of json.meshes) {
27025
- for (const primitive of mesh.primitives) {
27026
- processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
26860
+ function decodePropertyTextures2(scenegraph, extension) {
26861
+ const schema = extension.schema;
26862
+ if (!schema) {
26863
+ return;
26864
+ }
26865
+ const schemaClasses = schema.classes;
26866
+ const { featureTextures } = extension;
26867
+ if (schemaClasses && featureTextures) {
26868
+ for (const schemaName in schemaClasses) {
26869
+ const schemaClass = schemaClasses[schemaName];
26870
+ const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
26871
+ if (featureTexture) {
26872
+ handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
27027
26873
  }
27028
26874
  }
27029
26875
  }
27030
26876
  }
27031
- function decodePropertyTables(scenegraph, extension) {
26877
+ function decodePropertyTables2(scenegraph, extension) {
27032
26878
  const schema = extension.schema;
27033
26879
  if (!schema) {
27034
26880
  return;
27035
26881
  }
27036
26882
  const schemaClasses = schema.classes;
27037
- const propertyTables = extension.propertyTables;
26883
+ const propertyTables = extension.featureTables;
27038
26884
  if (schemaClasses && propertyTables) {
27039
26885
  for (const schemaName in schemaClasses) {
27040
- const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
26886
+ const propertyTable = findPropertyTableByClass2(propertyTables, schemaName);
27041
26887
  if (propertyTable) {
27042
- processPropertyTable(scenegraph, schema, propertyTable);
26888
+ processPropertyTable2(scenegraph, schema, propertyTable);
27043
26889
  }
27044
26890
  }
27045
26891
  }
27046
26892
  }
27047
- function findPropertyTableByClass(propertyTables, schemaClassName) {
27048
- for (const propertyTable of propertyTables) {
26893
+ function findPropertyTableByClass2(propertyTables, schemaClassName) {
26894
+ for (const propertyTableName in propertyTables) {
26895
+ const propertyTable = propertyTables[propertyTableName];
27049
26896
  if (propertyTable.class === schemaClassName) {
27050
26897
  return propertyTable;
27051
26898
  }
27052
26899
  }
27053
26900
  return null;
27054
26901
  }
27055
- function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
27056
- if (!propertyTextures) {
27057
- return;
27058
- }
27059
- const primitiveExtension = primitive.extensions?.[EXT_STRUCTURAL_METADATA_NAME];
27060
- const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;
27061
- if (!primitivePropertyTextureIndices) {
27062
- return;
27063
- }
27064
- for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
27065
- const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
27066
- processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
26902
+ function findFeatureTextureByClass(featureTextures, schemaClassName) {
26903
+ for (const featureTexturesName in featureTextures) {
26904
+ const featureTable = featureTextures[featureTexturesName];
26905
+ if (featureTable.class === schemaClassName) {
26906
+ return featureTable;
26907
+ }
27067
26908
  }
26909
+ return null;
27068
26910
  }
27069
- function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
27070
- if (!propertyTexture.properties) {
26911
+ function processPropertyTable2(scenegraph, schema, propertyTable) {
26912
+ if (!propertyTable.class) {
27071
26913
  return;
27072
26914
  }
27073
- if (!extension.dataAttributeNames) {
27074
- extension.dataAttributeNames = [];
27075
- }
27076
- const className = propertyTexture.class;
27077
- for (const propertyName in propertyTexture.properties) {
27078
- const attributeName = `${className}_${propertyName}`;
27079
- const textureInfoTopLevel = propertyTexture.properties?.[propertyName];
27080
- if (!textureInfoTopLevel) {
27081
- continue;
27082
- }
27083
- if (!textureInfoTopLevel.data) {
27084
- textureInfoTopLevel.data = [];
27085
- }
27086
- const featureTextureTable = textureInfoTopLevel.data;
27087
- const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
27088
- if (propertyData === null) {
27089
- continue;
27090
- }
27091
- primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
27092
- textureInfoTopLevel.data = featureTextureTable;
27093
- extension.dataAttributeNames.push(attributeName);
27094
- }
27095
- }
27096
- function processPropertyTable(scenegraph, schema, propertyTable) {
27097
26915
  const schemaClass = schema.classes?.[propertyTable.class];
27098
26916
  if (!schemaClass) {
27099
26917
  throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
@@ -27103,76 +26921,83 @@ void main(void) {
27103
26921
  const classProperty = schemaClass.properties[propertyName];
27104
26922
  const propertyTableProperty = propertyTable.properties?.[propertyName];
27105
26923
  if (propertyTableProperty) {
27106
- const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
26924
+ const data = getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
27107
26925
  propertyTableProperty.data = data;
27108
26926
  }
27109
26927
  }
27110
26928
  }
27111
- function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
27112
- let data = [];
27113
- const valuesBufferView = propertyTableProperty.values;
27114
- const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
27115
- const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements);
27116
- const stringOffsets = getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements);
27117
- switch (classProperty.type) {
27118
- case "SCALAR":
27119
- case "VEC2":
27120
- case "VEC3":
27121
- case "VEC4":
27122
- case "MAT2":
27123
- case "MAT3":
27124
- case "MAT4": {
27125
- data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
27126
- break;
27127
- }
27128
- case "BOOLEAN": {
27129
- throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
27130
- }
27131
- case "STRING": {
27132
- data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
27133
- break;
27134
- }
27135
- case "ENUM": {
27136
- data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
27137
- break;
26929
+ function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
26930
+ const attributeName = featureTexture.class;
26931
+ for (const propertyName in schemaClass.properties) {
26932
+ const featureTextureProperty = featureTexture?.properties?.[propertyName];
26933
+ if (featureTextureProperty) {
26934
+ const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
26935
+ featureTextureProperty.data = data;
27138
26936
  }
27139
- default:
27140
- throw new Error(`Unknown classProperty type ${classProperty.type}`);
26937
+ }
26938
+ }
26939
+ function getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) {
26940
+ let data = [];
26941
+ const bufferView = featureTableProperty.bufferView;
26942
+ const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
26943
+ const arrayOffsets = getArrayOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
26944
+ const stringOffsets = getStringOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
26945
+ if (classProperty.type === "STRING" || classProperty.componentType === "STRING") {
26946
+ data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
26947
+ } else if (isNumericProperty(classProperty)) {
26948
+ data = getPropertyDataNumeric2(classProperty, numberOfFeatures, dataArray, arrayOffsets);
27141
26949
  }
27142
26950
  return data;
27143
26951
  }
27144
- function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
27145
- if (classProperty.array && // `count` is a number of array elements. May only be defined when `array` is true.
27146
- // If `count` is NOT defined, it's a VARIABLE-length array
27147
- typeof classProperty.count === "undefined" && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
27148
- typeof propertyTableProperty.arrayOffsets !== "undefined") {
27149
- return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || "UINT32", numberOfElements);
26952
+ function getArrayOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
26953
+ if (classProperty.type === "ARRAY" && // `componentCount` is a number of fixed-length array elements.
26954
+ // If `componentCount` is NOT defined, it's a VARIABLE-length array
26955
+ typeof classProperty.componentCount === "undefined" && // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.
26956
+ typeof propertyTableProperty.arrayOffsetBufferView !== "undefined") {
26957
+ return getOffsetsForProperty(
26958
+ scenegraph,
26959
+ propertyTableProperty.arrayOffsetBufferView,
26960
+ propertyTableProperty.offsetType || "UINT32",
26961
+ // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
26962
+ numberOfElements
26963
+ );
27150
26964
  }
27151
26965
  return null;
27152
26966
  }
27153
- function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
27154
- if (typeof propertyTableProperty.stringOffsets !== "undefined") {
27155
- return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || "UINT32", numberOfElements);
26967
+ function getStringOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
26968
+ if (typeof propertyTableProperty.stringOffsetBufferView !== "undefined") {
26969
+ return getOffsetsForProperty(
26970
+ scenegraph,
26971
+ propertyTableProperty.stringOffsetBufferView,
26972
+ propertyTableProperty.offsetType || "UINT32",
26973
+ // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
26974
+ numberOfElements
26975
+ );
27156
26976
  }
27157
26977
  return null;
27158
26978
  }
27159
- function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
27160
- const isArray2 = classProperty.array;
27161
- const arrayCount = classProperty.count;
27162
- const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
26979
+ function isNumericProperty(schemaProperty) {
26980
+ const types = [
26981
+ "UINT8",
26982
+ "INT16",
26983
+ "UINT16",
26984
+ "INT32",
26985
+ "UINT32",
26986
+ "INT64",
26987
+ "UINT64",
26988
+ "FLOAT32",
26989
+ "FLOAT64"
26990
+ ];
26991
+ return types.includes(schemaProperty.type) || typeof schemaProperty.componentType !== "undefined" && types.includes(schemaProperty.componentType);
26992
+ }
26993
+ function getPropertyDataNumeric2(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
26994
+ const isArray2 = classProperty.type === "ARRAY";
26995
+ const arrayCount = classProperty.componentCount;
26996
+ const attributeType = "SCALAR";
26997
+ const componentType = classProperty.componentType || classProperty.type;
26998
+ const elementSize = getArrayElementByteSize(attributeType, componentType);
27163
26999
  const elementCount = valuesDataBytes.byteLength / elementSize;
27164
- let valuesData;
27165
- if (classProperty.componentType) {
27166
- valuesData = convertRawBufferToMetadataArray(
27167
- valuesDataBytes,
27168
- classProperty.type,
27169
- // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
27170
- classProperty.componentType,
27171
- elementCount
27172
- );
27173
- } else {
27174
- valuesData = valuesDataBytes;
27175
- }
27000
+ const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount);
27176
27001
  if (isArray2) {
27177
27002
  if (arrayOffsets) {
27178
27003
  return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
@@ -27184,443 +27009,618 @@ void main(void) {
27184
27009
  }
27185
27010
  return valuesData;
27186
27011
  }
27187
- function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
27188
- const enumType = classProperty.enumType;
27189
- if (!enumType) {
27190
- throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM");
27191
- }
27192
- const enumEntry = schema.enums?.[enumType];
27193
- if (!enumEntry) {
27194
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`);
27195
- }
27196
- const enumValueType = enumEntry.valueType || "UINT16";
27197
- const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
27198
- const elementCount = valuesDataBytes.byteLength / elementSize;
27199
- let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount);
27200
- if (!valuesData) {
27201
- valuesData = valuesDataBytes;
27202
- }
27203
- if (classProperty.array) {
27204
- if (arrayOffsets) {
27205
- return parseVariableLengthArrayENUM({
27206
- valuesData,
27207
- numberOfElements,
27208
- arrayOffsets,
27209
- valuesDataBytesLength: valuesDataBytes.length,
27210
- elementSize,
27211
- enumEntry
27212
- });
27213
- }
27214
- const arrayCount = classProperty.count;
27215
- if (arrayCount) {
27216
- return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
27217
- }
27012
+ function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
27013
+ const json = scenegraph.gltf.json;
27014
+ if (!json.meshes) {
27218
27015
  return [];
27219
27016
  }
27220
- return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);
27221
- }
27222
- function parseVariableLengthArrayENUM(params) {
27223
- const { valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry } = params;
27224
- const attributeValueArray = [];
27225
- for (let index = 0; index < numberOfElements; index++) {
27226
- const arrayOffset = arrayOffsets[index];
27227
- const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
27228
- if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
27229
- break;
27230
- }
27231
- const typedArrayOffset = arrayOffset / elementSize;
27232
- const elementCount = arrayByteSize / elementSize;
27233
- const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
27234
- attributeValueArray.push(array);
27235
- }
27236
- return attributeValueArray;
27237
- }
27238
- function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
27239
- const attributeValueArray = [];
27240
- for (let index = 0; index < numberOfElements; index++) {
27241
- const elementOffset = arrayCount * index;
27242
- const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);
27243
- attributeValueArray.push(array);
27244
- }
27245
- return attributeValueArray;
27246
- }
27247
- function getEnumsArray(valuesData, offset, count, enumEntry) {
27248
- const array = [];
27249
- for (let i = 0; i < count; i++) {
27250
- if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {
27251
- array.push("");
27252
- } else {
27253
- const value = valuesData[offset + i];
27254
- const enumObject = getEnumByValue(enumEntry, value);
27255
- if (enumObject) {
27256
- array.push(enumObject.name);
27257
- } else {
27258
- array.push("");
27259
- }
27260
- }
27261
- }
27262
- return array;
27263
- }
27264
- function getEnumByValue(enumEntry, value) {
27265
- for (const enumValue of enumEntry.values) {
27266
- if (enumValue.value === value) {
27267
- return enumValue;
27017
+ const featureTextureTable = [];
27018
+ for (const mesh of json.meshes) {
27019
+ for (const primitive of mesh.primitives) {
27020
+ processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
27268
27021
  }
27269
27022
  }
27270
- return null;
27023
+ return featureTextureTable;
27271
27024
  }
27272
- var SCHEMA_CLASS_ID_DEFAULT = "schemaClassId";
27273
- function encodeExtStructuralMetadata(scenegraph, options) {
27274
- const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
27275
- if (!extension) {
27025
+ function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
27026
+ const textureInfoTopLevel = {
27027
+ channels: featureTextureProperty.channels,
27028
+ ...featureTextureProperty.texture
27029
+ };
27030
+ const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
27031
+ if (!propertyData) {
27276
27032
  return;
27277
27033
  }
27278
- if (extension.propertyTables) {
27279
- for (const table of extension.propertyTables) {
27280
- const classId = table.class;
27281
- const schemaClass = extension.schema?.classes?.[classId];
27282
- if (table.properties && schemaClass) {
27283
- encodeProperties(table, schemaClass, scenegraph);
27284
- }
27285
- }
27286
- }
27034
+ primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
27287
27035
  }
27288
- function encodeProperties(table, schemaClass, scenegraph) {
27289
- for (const propertyName in table.properties) {
27290
- const data = table.properties[propertyName].data;
27291
- if (data) {
27292
- const classProperty = schemaClass.properties[propertyName];
27293
- if (classProperty) {
27294
- const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph);
27295
- table.properties[propertyName] = tableProperty;
27296
- }
27297
- }
27036
+
27037
+ // ../../node_modules/@loaders.gl/gltf/dist/lib/utils/version.js
27038
+ var VERSION10 = true ? "4.4.3" : "latest";
27039
+
27040
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/utils/version.js
27041
+ var VERSION11 = true ? "4.4.3" : "latest";
27042
+
27043
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/parsers/basis-module-loader.js
27044
+ var BASIS_EXTERNAL_LIBRARIES = {
27045
+ /** Basis transcoder, javascript wrapper part */
27046
+ TRANSCODER: "basis_transcoder.js",
27047
+ /** Basis transcoder, compiled web assembly part */
27048
+ TRANSCODER_WASM: "basis_transcoder.wasm",
27049
+ /** Basis encoder, javascript wrapper part */
27050
+ ENCODER: "basis_encoder.js",
27051
+ /** Basis encoder, compiled web assembly part */
27052
+ ENCODER_WASM: "basis_encoder.wasm"
27053
+ };
27054
+ var loadBasisTranscoderPromise;
27055
+ async function loadBasisTranscoderModule(options) {
27056
+ registerJSModules(options.modules);
27057
+ const basis = getJSModuleOrNull("basis");
27058
+ if (basis) {
27059
+ return basis;
27298
27060
  }
27061
+ loadBasisTranscoderPromise ||= loadBasisTranscoder(options);
27062
+ return await loadBasisTranscoderPromise;
27299
27063
  }
27300
- function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) {
27301
- let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
27302
- if (!extension) {
27303
- extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME);
27304
- }
27305
- extension.schema = createSchema(propertyAttributes, classId, extension.schema);
27306
- const table = createPropertyTable(propertyAttributes, classId, extension.schema);
27307
- if (!extension.propertyTables) {
27308
- extension.propertyTables = [];
27309
- }
27310
- return extension.propertyTables.push(table) - 1;
27064
+ async function loadBasisTranscoder(options) {
27065
+ let BASIS2 = null;
27066
+ let wasmBinary = null;
27067
+ [BASIS2, wasmBinary] = await Promise.all([
27068
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, "textures", options),
27069
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, "textures", options)
27070
+ ]);
27071
+ BASIS2 = BASIS2 || globalThis.BASIS;
27072
+ return await initializeBasisTranscoderModule(BASIS2, wasmBinary);
27311
27073
  }
27312
- function createSchema(propertyAttributes, classId, schemaToUpdate) {
27313
- const schema = schemaToUpdate ?? {
27314
- id: "schema_id"
27315
- };
27316
- const schemaClass = {
27317
- properties: {}
27318
- };
27319
- for (const attribute of propertyAttributes) {
27320
- const classProperty = {
27321
- type: attribute.elementType,
27322
- componentType: attribute.componentType
27323
- };
27324
- schemaClass.properties[attribute.name] = classProperty;
27074
+ function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
27075
+ const options = {};
27076
+ if (wasmBinary) {
27077
+ options.wasmBinary = wasmBinary;
27325
27078
  }
27326
- schema.classes = {};
27327
- schema.classes[classId] = schemaClass;
27328
- return schema;
27079
+ return new Promise((resolve2) => {
27080
+ BasisModule(options).then((module) => {
27081
+ const { BasisFile, initializeBasis } = module;
27082
+ initializeBasis();
27083
+ resolve2({ BasisFile });
27084
+ });
27085
+ });
27329
27086
  }
27330
- function createPropertyTable(propertyAttributes, classId, schema) {
27331
- const table = {
27332
- class: classId,
27333
- count: 0
27334
- };
27335
- let count = 0;
27336
- const schemaClass = schema.classes?.[classId];
27337
- for (const attribute of propertyAttributes) {
27338
- if (count === 0) {
27339
- count = attribute.values.length;
27340
- }
27341
- if (count !== attribute.values.length && attribute.values.length) {
27342
- throw new Error("Illegal values in attributes");
27343
- }
27344
- const classProperty = schemaClass?.properties[attribute.name];
27345
- if (classProperty) {
27346
- if (!table.properties) {
27347
- table.properties = {};
27348
- }
27349
- table.properties[attribute.name] = { values: 0, data: attribute.values };
27350
- }
27087
+ var loadBasisEncoderPromise;
27088
+ async function loadBasisEncoderModule(options) {
27089
+ const modules = options.modules || {};
27090
+ if (modules.basisEncoder) {
27091
+ return modules.basisEncoder;
27351
27092
  }
27352
- table.count = count;
27353
- return table;
27093
+ loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
27094
+ return await loadBasisEncoderPromise;
27354
27095
  }
27355
- function createPropertyTableProperty(values, classProperty, scenegraph) {
27356
- const prop = { values: 0 };
27357
- if (classProperty.type === "STRING") {
27358
- const { stringData, stringOffsets } = createPropertyDataString(values);
27359
- prop.stringOffsets = createBufferView(stringOffsets, scenegraph);
27360
- prop.values = createBufferView(stringData, scenegraph);
27361
- } else if (classProperty.type === "SCALAR" && classProperty.componentType) {
27362
- const data = createPropertyDataScalar(values, classProperty.componentType);
27363
- prop.values = createBufferView(data, scenegraph);
27096
+ async function loadBasisEncoder(options) {
27097
+ let BASIS_ENCODER = null;
27098
+ let wasmBinary = null;
27099
+ [BASIS_ENCODER, wasmBinary] = await Promise.all([
27100
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, "textures", options),
27101
+ await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, "textures", options)
27102
+ ]);
27103
+ BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
27104
+ return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
27105
+ }
27106
+ function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
27107
+ const options = {};
27108
+ if (wasmBinary) {
27109
+ options.wasmBinary = wasmBinary;
27364
27110
  }
27365
- return prop;
27111
+ return new Promise((resolve2) => {
27112
+ BasisEncoderModule(options).then((module) => {
27113
+ const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
27114
+ initializeBasis();
27115
+ resolve2({ BasisFile, KTX2File, BasisEncoder });
27116
+ });
27117
+ });
27366
27118
  }
27367
- var COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = {
27368
- INT8: Int8Array,
27369
- UINT8: Uint8Array,
27370
- INT16: Int16Array,
27371
- UINT16: Uint16Array,
27372
- INT32: Int32Array,
27373
- UINT32: Uint32Array,
27374
- INT64: Int32Array,
27375
- UINT64: Uint32Array,
27376
- FLOAT32: Float32Array,
27377
- FLOAT64: Float64Array
27119
+
27120
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/gl-extensions.js
27121
+ var GL_RGBA4 = 32854;
27122
+ var GL_RGBA8 = 32856;
27123
+ var GL_RGB565 = 36194;
27124
+ var GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
27125
+ var GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
27126
+ var GL_COMPRESSED_RGBA8_ETC2_EAC = 37493;
27127
+ var GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840;
27128
+ var GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842;
27129
+ var GL_COMPRESSED_RGB_ETC1_WEBGL = 36196;
27130
+ var GL_COMPRESSED_RGB_ATC_WEBGL = 35986;
27131
+ var GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798;
27132
+ var GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808;
27133
+ var GL_COMPRESSED_RED_RGTC1_EXT = 36283;
27134
+ var GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 36285;
27135
+ var GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 36492;
27136
+
27137
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/utils/detect-supported-texture-formats.js
27138
+ var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
27139
+ var WEBGL_TEXTURE_FORMATS = {
27140
+ /* eslint-disable camelcase */
27141
+ WEBGL_compressed_texture_s3tc: [
27142
+ "bc1-rgb-unorm-webgl",
27143
+ "bc1-rgba-unorm",
27144
+ "bc2-rgba-unorm",
27145
+ "bc3-rgba-unorm"
27146
+ ],
27147
+ WEBGL_compressed_texture_s3tc_srgb: [
27148
+ "bc1-rgb-unorm-srgb-webgl",
27149
+ "bc1-rgba-unorm-srgb",
27150
+ "bc2-rgba-unorm-srgb",
27151
+ "bc3-rgba-unorm-srgb"
27152
+ ],
27153
+ EXT_texture_compression_rgtc: ["bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm"],
27154
+ EXT_texture_compression_bptc: [
27155
+ "bc6h-rgb-ufloat",
27156
+ "bc6h-rgb-float",
27157
+ "bc7-rgba-unorm",
27158
+ "bc7-rgba-unorm-srgb"
27159
+ ],
27160
+ WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
27161
+ WEBGL_compressed_texture_etc: [
27162
+ "etc2-rgb8unorm",
27163
+ "etc2-rgb8unorm-srgb",
27164
+ "etc2-rgb8a1unorm",
27165
+ "etc2-rgb8a1unorm-srgb",
27166
+ "etc2-rgba8unorm",
27167
+ "etc2-rgba8unorm-srgb",
27168
+ "eac-r11unorm",
27169
+ "eac-r11snorm",
27170
+ "eac-rg11unorm",
27171
+ "eac-rg11snorm"
27172
+ ],
27173
+ WEBGL_compressed_texture_pvrtc: [
27174
+ "pvrtc-rgb4unorm-webgl",
27175
+ "pvrtc-rgba4unorm-webgl",
27176
+ "pvrtc-rgb2unorm-webgl",
27177
+ "pvrtc-rgba2unorm-webgl"
27178
+ ],
27179
+ WEBGL_compressed_texture_atc: [
27180
+ "atc-rgb-unorm-webgl",
27181
+ "atc-rgba-unorm-webgl",
27182
+ "atc-rgbai-unorm-webgl"
27183
+ ],
27184
+ WEBGL_compressed_texture_astc: [
27185
+ "astc-4x4-unorm",
27186
+ "astc-4x4-unorm-srgb",
27187
+ "astc-5x4-unorm",
27188
+ "astc-5x4-unorm-srgb",
27189
+ "astc-5x5-unorm",
27190
+ "astc-5x5-unorm-srgb",
27191
+ "astc-6x5-unorm",
27192
+ "astc-6x5-unorm-srgb",
27193
+ "astc-6x6-unorm",
27194
+ "astc-6x6-unorm-srgb",
27195
+ "astc-8x5-unorm",
27196
+ "astc-8x5-unorm-srgb",
27197
+ "astc-8x6-unorm",
27198
+ "astc-8x6-unorm-srgb",
27199
+ "astc-8x8-unorm",
27200
+ "astc-8x8-unorm-srgb",
27201
+ "astc-10x5-unorm",
27202
+ "astc-10x5-unorm-srgb",
27203
+ "astc-10x6-unorm",
27204
+ "astc-10x6-unorm-srgb",
27205
+ "astc-10x8-unorm",
27206
+ "astc-10x8-unorm-srgb",
27207
+ "astc-10x10-unorm",
27208
+ "astc-10x10-unorm-srgb",
27209
+ "astc-12x10-unorm",
27210
+ "astc-12x10-unorm-srgb",
27211
+ "astc-12x12-unorm",
27212
+ "astc-12x12-unorm-srgb"
27213
+ ]
27214
+ /* eslint-enable camelcase */
27378
27215
  };
27379
- function createPropertyDataScalar(array, componentType) {
27380
- const numberArray = [];
27381
- for (const value of array) {
27382
- numberArray.push(Number(value));
27383
- }
27384
- const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType];
27385
- if (!Construct) {
27386
- throw new Error("Illegal component type");
27216
+ var textureFormats = null;
27217
+ function detectSupportedTextureFormats(gl) {
27218
+ if (!textureFormats) {
27219
+ gl = gl || getWebGLContext() || void 0;
27220
+ textureFormats = /* @__PURE__ */ new Set();
27221
+ for (const prefix of BROWSER_PREFIXES) {
27222
+ for (const extension in WEBGL_TEXTURE_FORMATS) {
27223
+ if (gl && gl.getExtension(`${prefix}${extension}`)) {
27224
+ for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
27225
+ textureFormats.add(textureFormat);
27226
+ }
27227
+ }
27228
+ }
27229
+ }
27387
27230
  }
27388
- return new Construct(numberArray);
27231
+ return textureFormats;
27389
27232
  }
27390
- function createPropertyDataString(strings) {
27391
- const utf8Encode = new TextEncoder();
27392
- const arr = [];
27393
- let len5 = 0;
27394
- for (const str7 of strings) {
27395
- const uint8Array = utf8Encode.encode(str7);
27396
- len5 += uint8Array.length;
27397
- arr.push(uint8Array);
27398
- }
27399
- const strArray = new Uint8Array(len5);
27400
- const strOffsets = [];
27401
- let offset = 0;
27402
- for (const str7 of arr) {
27403
- strArray.set(str7, offset);
27404
- strOffsets.push(offset);
27405
- offset += str7.length;
27233
+ function getWebGLContext() {
27234
+ try {
27235
+ const canvas = document.createElement("canvas");
27236
+ return canvas.getContext("webgl");
27237
+ } catch (error) {
27238
+ return null;
27406
27239
  }
27407
- strOffsets.push(offset);
27408
- const stringOffsetsTypedArray = new Uint32Array(strOffsets);
27409
- return { stringData: strArray, stringOffsets: stringOffsetsTypedArray };
27410
27240
  }
27411
- function createBufferView(typedArray, scenegraph) {
27412
- scenegraph.gltf.buffers.push({
27413
- arrayBuffer: ensureArrayBuffer(typedArray.buffer),
27414
- byteOffset: typedArray.byteOffset,
27415
- byteLength: typedArray.byteLength
27416
- });
27417
- return scenegraph.addBufferView(typedArray);
27241
+
27242
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/parsers/parse-ktx.js
27243
+ var KTX2_ID = [
27244
+ // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
27245
+ 171,
27246
+ 75,
27247
+ 84,
27248
+ 88,
27249
+ 32,
27250
+ 50,
27251
+ 48,
27252
+ 187,
27253
+ 13,
27254
+ 10,
27255
+ 26,
27256
+ 10
27257
+ ];
27258
+ function isKTX(data) {
27259
+ const id = new Uint8Array(data);
27260
+ const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || // '´'
27261
+ id[1] !== KTX2_ID[1] || // 'K'
27262
+ id[2] !== KTX2_ID[2] || // 'T'
27263
+ id[3] !== KTX2_ID[3] || // 'X'
27264
+ id[4] !== KTX2_ID[4] || // ' '
27265
+ id[5] !== KTX2_ID[5] || // '2'
27266
+ id[6] !== KTX2_ID[6] || // '0'
27267
+ id[7] !== KTX2_ID[7] || // 'ª'
27268
+ id[8] !== KTX2_ID[8] || // '\r'
27269
+ id[9] !== KTX2_ID[9] || // '\n'
27270
+ id[10] !== KTX2_ID[10] || // '\x1A'
27271
+ id[11] !== KTX2_ID[11];
27272
+ return !notKTX;
27418
27273
  }
27419
27274
 
27420
- // ../../node_modules/@loaders.gl/gltf/dist/lib/extensions/deprecated/EXT_feature_metadata.js
27421
- var EXT_feature_metadata_exports = {};
27422
- __export(EXT_feature_metadata_exports, {
27423
- decode: () => decode3,
27424
- name: () => name3
27425
- });
27426
- var EXT_FEATURE_METADATA_NAME = "EXT_feature_metadata";
27427
- var name3 = EXT_FEATURE_METADATA_NAME;
27428
- async function decode3(gltfData, options) {
27429
- const scenegraph = new GLTFScenegraph(gltfData);
27430
- decodeExtFeatureMetadata(scenegraph, options);
27431
- }
27432
- function decodeExtFeatureMetadata(scenegraph, options) {
27433
- if (!options.gltf?.loadBuffers) {
27434
- return;
27435
- }
27436
- const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
27437
- if (!extension) {
27438
- return;
27275
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/lib/parsers/parse-basis.js
27276
+ var basisTranscodingLock = Promise.resolve();
27277
+ var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
27278
+ etc1: {
27279
+ basisFormat: 0,
27280
+ compressed: true,
27281
+ format: GL_COMPRESSED_RGB_ETC1_WEBGL,
27282
+ textureFormat: "etc1-rgb-unorm-webgl"
27283
+ },
27284
+ etc2: {
27285
+ basisFormat: 1,
27286
+ compressed: true,
27287
+ format: GL_COMPRESSED_RGBA8_ETC2_EAC,
27288
+ textureFormat: "etc2-rgba8unorm"
27289
+ },
27290
+ bc1: {
27291
+ basisFormat: 2,
27292
+ compressed: true,
27293
+ format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
27294
+ textureFormat: "bc1-rgb-unorm-webgl"
27295
+ },
27296
+ bc3: {
27297
+ basisFormat: 3,
27298
+ compressed: true,
27299
+ format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
27300
+ textureFormat: "bc3-rgba-unorm"
27301
+ },
27302
+ bc4: {
27303
+ basisFormat: 4,
27304
+ compressed: true,
27305
+ format: GL_COMPRESSED_RED_RGTC1_EXT,
27306
+ textureFormat: "bc4-r-unorm"
27307
+ },
27308
+ bc5: {
27309
+ basisFormat: 5,
27310
+ compressed: true,
27311
+ format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
27312
+ textureFormat: "bc5-rg-unorm"
27313
+ },
27314
+ "bc7-m6-opaque-only": {
27315
+ basisFormat: 6,
27316
+ compressed: true,
27317
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
27318
+ textureFormat: "bc7-rgba-unorm"
27319
+ },
27320
+ "bc7-m5": {
27321
+ basisFormat: 7,
27322
+ compressed: true,
27323
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
27324
+ textureFormat: "bc7-rgba-unorm"
27325
+ },
27326
+ "pvrtc1-4-rgb": {
27327
+ basisFormat: 8,
27328
+ compressed: true,
27329
+ format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
27330
+ textureFormat: "pvrtc-rgb4unorm-webgl"
27331
+ },
27332
+ "pvrtc1-4-rgba": {
27333
+ basisFormat: 9,
27334
+ compressed: true,
27335
+ format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
27336
+ textureFormat: "pvrtc-rgba4unorm-webgl"
27337
+ },
27338
+ "astc-4x4": {
27339
+ basisFormat: 10,
27340
+ compressed: true,
27341
+ format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
27342
+ textureFormat: "astc-4x4-unorm"
27343
+ },
27344
+ "atc-rgb": {
27345
+ basisFormat: 11,
27346
+ compressed: true,
27347
+ format: GL_COMPRESSED_RGB_ATC_WEBGL,
27348
+ textureFormat: "atc-rgb-unorm-webgl"
27349
+ },
27350
+ "atc-rgba-interpolated-alpha": {
27351
+ basisFormat: 12,
27352
+ compressed: true,
27353
+ format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
27354
+ textureFormat: "atc-rgbai-unorm-webgl"
27355
+ },
27356
+ rgba32: {
27357
+ basisFormat: 13,
27358
+ compressed: false,
27359
+ format: GL_RGBA8,
27360
+ textureFormat: "rgba8unorm"
27361
+ },
27362
+ rgb565: {
27363
+ basisFormat: 14,
27364
+ compressed: false,
27365
+ format: GL_RGB565,
27366
+ textureFormat: "rgb565unorm-webgl"
27367
+ },
27368
+ bgr565: {
27369
+ basisFormat: 15,
27370
+ compressed: false,
27371
+ format: GL_RGB565,
27372
+ textureFormat: "rgb565unorm-webgl"
27373
+ },
27374
+ rgba4444: {
27375
+ basisFormat: 16,
27376
+ compressed: false,
27377
+ format: GL_RGBA4,
27378
+ textureFormat: "rgba4unorm-webgl"
27439
27379
  }
27440
- if (options.gltf?.loadImages) {
27441
- decodePropertyTextures2(scenegraph, extension);
27380
+ };
27381
+ var BASIS_FORMATS = Object.freeze(Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS));
27382
+ async function withBasisTranscodingLock(transcode) {
27383
+ const previousLock = basisTranscodingLock;
27384
+ let releaseLock;
27385
+ basisTranscodingLock = new Promise((resolve2) => {
27386
+ releaseLock = resolve2;
27387
+ });
27388
+ await previousLock;
27389
+ try {
27390
+ return await transcode();
27391
+ } finally {
27392
+ releaseLock();
27442
27393
  }
27443
- decodePropertyTables2(scenegraph, extension);
27444
27394
  }
27445
- function decodePropertyTextures2(scenegraph, extension) {
27446
- const schema = extension.schema;
27447
- if (!schema) {
27448
- return;
27449
- }
27450
- const schemaClasses = schema.classes;
27451
- const { featureTextures } = extension;
27452
- if (schemaClasses && featureTextures) {
27453
- for (const schemaName in schemaClasses) {
27454
- const schemaClass = schemaClasses[schemaName];
27455
- const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
27456
- if (featureTexture) {
27457
- handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
27395
+ async function parseBasis(data, options = {}) {
27396
+ const loadLibraryOptions = extractLoadLibraryOptions(options);
27397
+ return await withBasisTranscodingLock(async () => {
27398
+ if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
27399
+ if (isKTX(data)) {
27400
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
27401
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
27458
27402
  }
27403
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
27404
+ return parseBasisFile(BasisFile, data, options);
27459
27405
  }
27460
- }
27461
- }
27462
- function decodePropertyTables2(scenegraph, extension) {
27463
- const schema = extension.schema;
27464
- if (!schema) {
27465
- return;
27466
- }
27467
- const schemaClasses = schema.classes;
27468
- const propertyTables = extension.featureTables;
27469
- if (schemaClasses && propertyTables) {
27470
- for (const schemaName in schemaClasses) {
27471
- const propertyTable = findPropertyTableByClass2(propertyTables, schemaName);
27472
- if (propertyTable) {
27473
- processPropertyTable2(scenegraph, schema, propertyTable);
27474
- }
27406
+ switch (options.basis.module) {
27407
+ case "encoder":
27408
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
27409
+ switch (options.basis.containerFormat) {
27410
+ case "ktx2":
27411
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
27412
+ case "basis":
27413
+ default:
27414
+ return parseBasisFile(fileConstructors.BasisFile, data, options);
27415
+ }
27416
+ case "transcoder":
27417
+ default:
27418
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
27419
+ return parseBasisFile(BasisFile, data, options);
27475
27420
  }
27476
- }
27421
+ });
27477
27422
  }
27478
- function findPropertyTableByClass2(propertyTables, schemaClassName) {
27479
- for (const propertyTableName in propertyTables) {
27480
- const propertyTable = propertyTables[propertyTableName];
27481
- if (propertyTable.class === schemaClassName) {
27482
- return propertyTable;
27423
+ function parseBasisFile(BasisFile, data, options) {
27424
+ const basisFile = new BasisFile(new Uint8Array(data));
27425
+ try {
27426
+ if (!basisFile.startTranscoding()) {
27427
+ throw new Error("Failed to start basis transcoding");
27483
27428
  }
27484
- }
27485
- return null;
27486
- }
27487
- function findFeatureTextureByClass(featureTextures, schemaClassName) {
27488
- for (const featureTexturesName in featureTextures) {
27489
- const featureTable = featureTextures[featureTexturesName];
27490
- if (featureTable.class === schemaClassName) {
27491
- return featureTable;
27429
+ const imageCount = basisFile.getNumImages();
27430
+ const images = [];
27431
+ for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
27432
+ const levelsCount = basisFile.getNumLevels(imageIndex);
27433
+ const levels = [];
27434
+ for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
27435
+ levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
27436
+ }
27437
+ images.push(levels);
27492
27438
  }
27439
+ return images;
27440
+ } finally {
27441
+ basisFile.close();
27442
+ basisFile.delete();
27493
27443
  }
27494
- return null;
27495
27444
  }
27496
- function processPropertyTable2(scenegraph, schema, propertyTable) {
27497
- if (!propertyTable.class) {
27498
- return;
27499
- }
27500
- const schemaClass = schema.classes?.[propertyTable.class];
27501
- if (!schemaClass) {
27502
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
27503
- }
27504
- const numberOfElements = propertyTable.count;
27505
- for (const propertyName in schemaClass.properties) {
27506
- const classProperty = schemaClass.properties[propertyName];
27507
- const propertyTableProperty = propertyTable.properties?.[propertyName];
27508
- if (propertyTableProperty) {
27509
- const data = getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
27510
- propertyTableProperty.data = data;
27511
- }
27445
+ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
27446
+ const width = basisFile.getImageWidth(imageIndex, levelIndex);
27447
+ const height = basisFile.getImageHeight(imageIndex, levelIndex);
27448
+ const hasAlpha = basisFile.getHasAlpha(
27449
+ /* imageIndex, levelIndex */
27450
+ );
27451
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
27452
+ const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
27453
+ const decodedData = new Uint8Array(decodedSize);
27454
+ if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
27455
+ throw new Error("failed to start Basis transcoding");
27512
27456
  }
27457
+ return {
27458
+ // standard loaders.gl image category payload
27459
+ shape: "texture-level",
27460
+ width,
27461
+ height,
27462
+ data: decodedData,
27463
+ compressed,
27464
+ ...format !== void 0 ? { format } : {},
27465
+ ...textureFormat !== void 0 ? { textureFormat } : {},
27466
+ // Additional fields
27467
+ // Add levelSize field.
27468
+ hasAlpha
27469
+ };
27513
27470
  }
27514
- function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
27515
- const attributeName = featureTexture.class;
27516
- for (const propertyName in schemaClass.properties) {
27517
- const featureTextureProperty = featureTexture?.properties?.[propertyName];
27518
- if (featureTextureProperty) {
27519
- const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
27520
- featureTextureProperty.data = data;
27471
+ function parseKTX2File(KTX2File, data, options) {
27472
+ const ktx2File = new KTX2File(new Uint8Array(data));
27473
+ try {
27474
+ if (!ktx2File.startTranscoding()) {
27475
+ throw new Error("failed to start KTX2 transcoding");
27476
+ }
27477
+ const levelsCount = ktx2File.getLevels();
27478
+ const levels = [];
27479
+ for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
27480
+ levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
27521
27481
  }
27482
+ return [levels];
27483
+ } finally {
27484
+ ktx2File.close();
27485
+ ktx2File.delete();
27522
27486
  }
27523
27487
  }
27524
- function getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) {
27525
- let data = [];
27526
- const bufferView = featureTableProperty.bufferView;
27527
- const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
27528
- const arrayOffsets = getArrayOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
27529
- const stringOffsets = getStringOffsetsForProperty2(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
27530
- if (classProperty.type === "STRING" || classProperty.componentType === "STRING") {
27531
- data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
27532
- } else if (isNumericProperty(classProperty)) {
27533
- data = getPropertyDataNumeric2(classProperty, numberOfFeatures, dataArray, arrayOffsets);
27488
+ function transcodeKTX2Image(ktx2File, levelIndex, options) {
27489
+ const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
27490
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
27491
+ const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
27492
+ const decodedData = new Uint8Array(decodedSize);
27493
+ if (!ktx2File.transcodeImage(
27494
+ decodedData,
27495
+ levelIndex,
27496
+ 0,
27497
+ 0,
27498
+ basisFormat,
27499
+ 0,
27500
+ -1,
27501
+ -1
27502
+ /* channel1 */
27503
+ )) {
27504
+ throw new Error("Failed to transcode KTX2 image");
27534
27505
  }
27535
- return data;
27506
+ return {
27507
+ // standard loaders.gl image category payload
27508
+ shape: "texture-level",
27509
+ width,
27510
+ height,
27511
+ data: decodedData,
27512
+ compressed,
27513
+ ...format !== void 0 ? { format } : {},
27514
+ ...textureFormat !== void 0 ? { textureFormat } : {},
27515
+ // Additional fields
27516
+ levelSize: decodedSize,
27517
+ hasAlpha: alphaFlag
27518
+ };
27536
27519
  }
27537
- function getArrayOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
27538
- if (classProperty.type === "ARRAY" && // `componentCount` is a number of fixed-length array elements.
27539
- // If `componentCount` is NOT defined, it's a VARIABLE-length array
27540
- typeof classProperty.componentCount === "undefined" && // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.
27541
- typeof propertyTableProperty.arrayOffsetBufferView !== "undefined") {
27542
- return getOffsetsForProperty(
27543
- scenegraph,
27544
- propertyTableProperty.arrayOffsetBufferView,
27545
- propertyTableProperty.offsetType || "UINT32",
27546
- // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
27547
- numberOfElements
27548
- );
27520
+ function getBasisOptions(options, hasAlpha) {
27521
+ let format = options.basis?.format || "auto";
27522
+ if (format === "auto") {
27523
+ format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
27549
27524
  }
27550
- return null;
27551
- }
27552
- function getStringOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
27553
- if (typeof propertyTableProperty.stringOffsetBufferView !== "undefined") {
27554
- return getOffsetsForProperty(
27555
- scenegraph,
27556
- propertyTableProperty.stringOffsetBufferView,
27557
- propertyTableProperty.offsetType || "UINT32",
27558
- // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
27559
- numberOfElements
27560
- );
27525
+ if (typeof format === "object") {
27526
+ format = hasAlpha ? format.alpha : format.noAlpha;
27561
27527
  }
27562
- return null;
27563
- }
27564
- function isNumericProperty(schemaProperty) {
27565
- const types = [
27566
- "UINT8",
27567
- "INT16",
27568
- "UINT16",
27569
- "INT32",
27570
- "UINT32",
27571
- "INT64",
27572
- "UINT64",
27573
- "FLOAT32",
27574
- "FLOAT64"
27575
- ];
27576
- return types.includes(schemaProperty.type) || typeof schemaProperty.componentType !== "undefined" && types.includes(schemaProperty.componentType);
27577
- }
27578
- function getPropertyDataNumeric2(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
27579
- const isArray2 = classProperty.type === "ARRAY";
27580
- const arrayCount = classProperty.componentCount;
27581
- const attributeType = "SCALAR";
27582
- const componentType = classProperty.componentType || classProperty.type;
27583
- const elementSize = getArrayElementByteSize(attributeType, componentType);
27584
- const elementCount = valuesDataBytes.byteLength / elementSize;
27585
- const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount);
27586
- if (isArray2) {
27587
- if (arrayOffsets) {
27588
- return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
27589
- }
27590
- if (arrayCount) {
27591
- return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
27592
- }
27593
- return [];
27528
+ const normalizedFormat = format.toLowerCase();
27529
+ const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
27530
+ if (!basisOutputOptions) {
27531
+ throw new Error(`Unknown Basis format ${format}`);
27594
27532
  }
27595
- return valuesData;
27533
+ return basisOutputOptions;
27596
27534
  }
27597
- function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
27598
- const json = scenegraph.gltf.json;
27599
- if (!json.meshes) {
27600
- return [];
27601
- }
27602
- const featureTextureTable = [];
27603
- for (const mesh of json.meshes) {
27604
- for (const primitive of mesh.primitives) {
27605
- processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
27606
- }
27535
+ function selectSupportedBasisFormat(supportedTextureFormats = detectSupportedTextureFormats()) {
27536
+ const textureFormats2 = new Set(supportedTextureFormats);
27537
+ if (hasSupportedTextureFormat(textureFormats2, ["astc-4x4-unorm", "astc-4x4-unorm-srgb"])) {
27538
+ return "astc-4x4";
27539
+ } else if (hasSupportedTextureFormat(textureFormats2, ["bc7-rgba-unorm", "bc7-rgba-unorm-srgb"])) {
27540
+ return {
27541
+ alpha: "bc7-m5",
27542
+ noAlpha: "bc7-m6-opaque-only"
27543
+ };
27544
+ } else if (hasSupportedTextureFormat(textureFormats2, [
27545
+ "bc1-rgb-unorm-webgl",
27546
+ "bc1-rgb-unorm-srgb-webgl",
27547
+ "bc1-rgba-unorm",
27548
+ "bc1-rgba-unorm-srgb",
27549
+ "bc2-rgba-unorm",
27550
+ "bc2-rgba-unorm-srgb",
27551
+ "bc3-rgba-unorm",
27552
+ "bc3-rgba-unorm-srgb"
27553
+ ])) {
27554
+ return {
27555
+ alpha: "bc3",
27556
+ noAlpha: "bc1"
27557
+ };
27558
+ } else if (hasSupportedTextureFormat(textureFormats2, [
27559
+ "pvrtc-rgb4unorm-webgl",
27560
+ "pvrtc-rgba4unorm-webgl",
27561
+ "pvrtc-rgb2unorm-webgl",
27562
+ "pvrtc-rgba2unorm-webgl"
27563
+ ])) {
27564
+ return {
27565
+ alpha: "pvrtc1-4-rgba",
27566
+ noAlpha: "pvrtc1-4-rgb"
27567
+ };
27568
+ } else if (hasSupportedTextureFormat(textureFormats2, [
27569
+ "etc2-rgb8unorm",
27570
+ "etc2-rgb8unorm-srgb",
27571
+ "etc2-rgb8a1unorm",
27572
+ "etc2-rgb8a1unorm-srgb",
27573
+ "etc2-rgba8unorm",
27574
+ "etc2-rgba8unorm-srgb",
27575
+ "eac-r11unorm",
27576
+ "eac-r11snorm",
27577
+ "eac-rg11unorm",
27578
+ "eac-rg11snorm"
27579
+ ])) {
27580
+ return "etc2";
27581
+ } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
27582
+ return "etc1";
27583
+ } else if (hasSupportedTextureFormat(textureFormats2, [
27584
+ "atc-rgb-unorm-webgl",
27585
+ "atc-rgba-unorm-webgl",
27586
+ "atc-rgbai-unorm-webgl"
27587
+ ])) {
27588
+ return {
27589
+ alpha: "atc-rgba-interpolated-alpha",
27590
+ noAlpha: "atc-rgb"
27591
+ };
27607
27592
  }
27608
- return featureTextureTable;
27593
+ return "rgb565";
27609
27594
  }
27610
- function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
27611
- const textureInfoTopLevel = {
27612
- channels: featureTextureProperty.channels,
27613
- ...featureTextureProperty.texture
27614
- };
27615
- const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
27616
- if (!propertyData) {
27617
- return;
27618
- }
27619
- primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
27595
+ function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
27596
+ return candidateTextureFormats.some((textureFormat) => supportedTextureFormats.has(textureFormat));
27620
27597
  }
27621
27598
 
27622
- // ../../node_modules/@loaders.gl/gltf/dist/lib/utils/version.js
27623
- var VERSION11 = true ? "4.4.1" : "latest";
27599
+ // ../../node_modules/@loaders.gl/gltf/node_modules/@loaders.gl/textures/dist/basis-loader.js
27600
+ var BasisWorkerLoader = {
27601
+ dataType: null,
27602
+ batchType: null,
27603
+ name: "Basis",
27604
+ id: "basis",
27605
+ module: "textures",
27606
+ version: VERSION11,
27607
+ worker: true,
27608
+ extensions: ["basis", "ktx2"],
27609
+ mimeTypes: ["application/octet-stream", "image/ktx2"],
27610
+ tests: ["sB"],
27611
+ binary: true,
27612
+ options: {
27613
+ basis: {
27614
+ format: "auto",
27615
+ containerFormat: "auto",
27616
+ module: "transcoder"
27617
+ }
27618
+ }
27619
+ };
27620
+ var BasisLoader = {
27621
+ ...BasisWorkerLoader,
27622
+ parse: parseBasis
27623
+ };
27624
27624
 
27625
27625
  // ../../node_modules/@loaders.gl/gltf/dist/lib/parsers/parse-glb.js
27626
27626
  var LITTLE_ENDIAN2 = true;
@@ -28907,7 +28907,7 @@ void main(void) {
28907
28907
  name: "glTF",
28908
28908
  id: "gltf",
28909
28909
  module: "gltf",
28910
- version: VERSION11,
28910
+ version: VERSION10,
28911
28911
  extensions: ["gltf", "glb"],
28912
28912
  mimeTypes: ["model/gltf+json", "model/gltf-binary"],
28913
28913
  text: true,
@@ -29672,7 +29672,7 @@ void main(void) {
29672
29672
  id: "3d-tiles-subtree",
29673
29673
  name: "3D Tiles Subtree",
29674
29674
  module: "3d-tiles",
29675
- version: VERSION9,
29675
+ version: VERSION8,
29676
29676
  extensions: ["subtree"],
29677
29677
  mimeTypes: ["application/octet-stream"],
29678
29678
  tests: ["subtree"],
@@ -31259,7 +31259,7 @@ void main(void) {
31259
31259
  id: "3d-tiles",
31260
31260
  name: "3D Tiles",
31261
31261
  module: "3d-tiles",
31262
- version: VERSION9,
31262
+ version: VERSION8,
31263
31263
  extensions: ["cmpt", "pnts", "b3dm", "i3dm"],
31264
31264
  mimeTypes: ["application/octet-stream"],
31265
31265
  tests: ["cmpt", "pnts", "b3dm", "i3dm"],
@@ -31654,7 +31654,6 @@ void main(void) {
31654
31654
  // src/terrain-layer/terrain-layer.ts
31655
31655
  var import_core49 = __toESM(require_core(), 1);
31656
31656
  var import_mesh_layers3 = __toESM(require_mesh_layers(), 1);
31657
- var import_core50 = __toESM(require_core(), 1);
31658
31657
 
31659
31658
  // ../../node_modules/@loaders.gl/terrain/dist/lib/decode-quantized-mesh.js
31660
31659
  var QUANTIZED_MESH_HEADER = /* @__PURE__ */ new Map([
@@ -32615,7 +32614,7 @@ void main(void) {
32615
32614
  }
32616
32615
 
32617
32616
  // ../../node_modules/@loaders.gl/terrain/dist/lib/utils/version.js
32618
- var VERSION12 = true ? "4.4.1" : "latest";
32617
+ var VERSION12 = true ? "4.4.3" : "latest";
32619
32618
 
32620
32619
  // ../../node_modules/@loaders.gl/terrain/dist/terrain-loader.js
32621
32620
  var TerrainLoader = {
@@ -32807,7 +32806,7 @@ void main(void) {
32807
32806
  mesh,
32808
32807
  texture,
32809
32808
  _instanced: false,
32810
- coordinateSystem: import_core50.COORDINATE_SYSTEM.CARTESIAN,
32809
+ coordinateSystem: import_core49.COORDINATE_SYSTEM.CARTESIAN,
32811
32810
  getPosition: (d2) => [0, 0, 0],
32812
32811
  getColor: color,
32813
32812
  wireframe,
@@ -32852,7 +32851,8 @@ void main(void) {
32852
32851
  onTileError,
32853
32852
  maxCacheSize,
32854
32853
  maxCacheByteSize,
32855
- refinementStrategy
32854
+ refinementStrategy,
32855
+ zoomOffset
32856
32856
  } = this.props;
32857
32857
  if (this.state.isTiled) {
32858
32858
  return new TileLayer(
@@ -32867,7 +32867,9 @@ void main(void) {
32867
32867
  elevationData: urlTemplateToUpdateTrigger(elevationData),
32868
32868
  texture: urlTemplateToUpdateTrigger(texture),
32869
32869
  meshMaxError,
32870
- elevationDecoder
32870
+ elevationDecoder,
32871
+ projectionMode: this.context.viewport.projectionMode,
32872
+ zoomOffset
32871
32873
  }
32872
32874
  },
32873
32875
  onViewportLoad: this.onViewportLoad.bind(this),
@@ -32882,7 +32884,8 @@ void main(void) {
32882
32884
  onTileError,
32883
32885
  maxCacheSize,
32884
32886
  maxCacheByteSize,
32885
- refinementStrategy
32887
+ refinementStrategy,
32888
+ zoomOffset
32886
32889
  }
32887
32890
  );
32888
32891
  }
@@ -32912,7 +32915,7 @@ void main(void) {
32912
32915
  var isTileSetURL = (url) => url.includes("{x}") && (url.includes("{y}") || url.includes("{-y}"));
32913
32916
 
32914
32917
  // src/mvt-layer/mvt-layer.ts
32915
- var import_core52 = __toESM(require_core(), 1);
32918
+ var import_core51 = __toESM(require_core(), 1);
32916
32919
  var import_layers9 = __toESM(require_layers(), 1);
32917
32920
  var import_extensions = __toESM(require_extensions(), 1);
32918
32921
 
@@ -34487,7 +34490,7 @@ void main(void) {
34487
34490
  };
34488
34491
 
34489
34492
  // ../../node_modules/@loaders.gl/mvt/dist/mvt-loader.js
34490
- var VERSION13 = true ? "4.4.1" : "latest";
34493
+ var VERSION13 = true ? "4.4.3" : "latest";
34491
34494
  var MVTWorkerLoader = {
34492
34495
  ...MVTFormat,
34493
34496
  dataType: null,
@@ -34768,12 +34771,12 @@ void main(void) {
34768
34771
  if (!this.context.viewport.resolution) {
34769
34772
  props.modelMatrix = modelMatrix;
34770
34773
  props.coordinateOrigin = [xOffset, yOffset, 0];
34771
- props.coordinateSystem = import_core52.COORDINATE_SYSTEM.CARTESIAN;
34774
+ props.coordinateSystem = import_core51.COORDINATE_SYSTEM.CARTESIAN;
34772
34775
  props.extensions = [...props.extensions || [], new import_extensions.ClipExtension()];
34773
34776
  }
34774
34777
  const subLayers = super.renderSubLayers(props);
34775
34778
  if (this.state.binary && !(subLayers instanceof import_layers9.GeoJsonLayer)) {
34776
- import_core52.log.warn("renderSubLayers() must return GeoJsonLayer when using binary:true")();
34779
+ import_core51.log.warn("renderSubLayers() must return GeoJsonLayer when using binary:true")();
34777
34780
  }
34778
34781
  return subLayers;
34779
34782
  }