@loaders.gl/gltf 4.4.0-alpha.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/dist.dev.js +491 -211
  2. package/dist/dist.min.js +1 -1
  3. package/dist/glb-loader.d.ts +9 -6
  4. package/dist/glb-loader.d.ts.map +1 -1
  5. package/dist/glb-loader.js +2 -2
  6. package/dist/glb-loader.js.map +1 -0
  7. package/dist/glb-writer.js +1 -0
  8. package/dist/glb-writer.js.map +1 -0
  9. package/dist/gltf-loader.d.ts +2 -3
  10. package/dist/gltf-loader.d.ts.map +1 -1
  11. package/dist/gltf-loader.js +6 -8
  12. package/dist/gltf-loader.js.map +1 -0
  13. package/dist/gltf-writer.js +1 -0
  14. package/dist/gltf-writer.js.map +1 -0
  15. package/dist/index.cjs +92 -56
  16. package/dist/index.cjs.map +4 -4
  17. package/dist/index.js +1 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lib/api/gltf-extensions.js +1 -0
  20. package/dist/lib/api/gltf-extensions.js.map +1 -0
  21. package/dist/lib/api/gltf-scenegraph.js +1 -0
  22. package/dist/lib/api/gltf-scenegraph.js.map +1 -0
  23. package/dist/lib/api/normalize-gltf-v1.js +1 -0
  24. package/dist/lib/api/normalize-gltf-v1.js.map +1 -0
  25. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  26. package/dist/lib/api/post-process-gltf.js +3 -1
  27. package/dist/lib/api/post-process-gltf.js.map +1 -0
  28. package/dist/lib/encoders/encode-glb.js +1 -0
  29. package/dist/lib/encoders/encode-glb.js.map +1 -0
  30. package/dist/lib/encoders/encode-gltf.js +1 -0
  31. package/dist/lib/encoders/encode-gltf.js.map +1 -0
  32. package/dist/lib/extensions/EXT_mesh_features.js +1 -0
  33. package/dist/lib/extensions/EXT_mesh_features.js.map +1 -0
  34. package/dist/lib/extensions/EXT_meshopt_compression.js +1 -0
  35. package/dist/lib/extensions/EXT_meshopt_compression.js.map +1 -0
  36. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  37. package/dist/lib/extensions/EXT_structural_metadata.js +3 -1
  38. package/dist/lib/extensions/EXT_structural_metadata.js.map +1 -0
  39. package/dist/lib/extensions/EXT_texture_webp.js +1 -0
  40. package/dist/lib/extensions/EXT_texture_webp.js.map +1 -0
  41. package/dist/lib/extensions/KHR_binary_gltf.js +1 -0
  42. package/dist/lib/extensions/KHR_binary_gltf.js.map +1 -0
  43. package/dist/lib/extensions/KHR_draco_mesh_compression.js +1 -0
  44. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
  45. package/dist/lib/extensions/KHR_texture_basisu.js +1 -0
  46. package/dist/lib/extensions/KHR_texture_basisu.js.map +1 -0
  47. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
  48. package/dist/lib/extensions/KHR_texture_transform.js +36 -14
  49. package/dist/lib/extensions/KHR_texture_transform.js.map +1 -0
  50. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +1 -0
  51. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
  52. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +1 -0
  53. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
  54. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +1 -0
  55. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
  56. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -0
  57. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
  58. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  59. package/dist/lib/extensions/utils/3d-tiles-utils.js +3 -1
  60. package/dist/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  61. package/dist/lib/gltf-utils/get-typed-array.d.ts +2 -2
  62. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
  63. package/dist/lib/gltf-utils/get-typed-array.js +1 -0
  64. package/dist/lib/gltf-utils/get-typed-array.js.map +1 -0
  65. package/dist/lib/gltf-utils/gltf-attribute-utils.js +1 -0
  66. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
  67. package/dist/lib/gltf-utils/gltf-constants.js +1 -0
  68. package/dist/lib/gltf-utils/gltf-constants.js.map +1 -0
  69. package/dist/lib/gltf-utils/gltf-utils.js +1 -0
  70. package/dist/lib/gltf-utils/gltf-utils.js.map +1 -0
  71. package/dist/lib/gltf-utils/resolve-url.d.ts +2 -1
  72. package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -1
  73. package/dist/lib/gltf-utils/resolve-url.js +15 -4
  74. package/dist/lib/gltf-utils/resolve-url.js.map +1 -0
  75. package/dist/lib/parsers/parse-glb.js +1 -0
  76. package/dist/lib/parsers/parse-glb.js.map +1 -0
  77. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  78. package/dist/lib/parsers/parse-gltf.js +13 -11
  79. package/dist/lib/parsers/parse-gltf.js.map +1 -0
  80. package/dist/lib/types/glb-types.js +1 -0
  81. package/dist/lib/types/glb-types.js.map +1 -0
  82. package/dist/lib/types/gltf-ext-feature-metadata-schema.js +1 -0
  83. package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  84. package/dist/lib/types/gltf-ext-mesh-features-schema.js +1 -0
  85. package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  86. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +1 -0
  87. package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  88. package/dist/lib/types/gltf-json-schema.js +1 -0
  89. package/dist/lib/types/gltf-json-schema.js.map +1 -0
  90. package/dist/lib/types/gltf-postprocessed-schema.js +1 -0
  91. package/dist/lib/types/gltf-postprocessed-schema.js.map +1 -0
  92. package/dist/lib/types/gltf-types.js +1 -0
  93. package/dist/lib/types/gltf-types.js.map +1 -0
  94. package/dist/lib/utils/assert.js +1 -0
  95. package/dist/lib/utils/assert.js.map +1 -0
  96. package/dist/lib/utils/version.js +2 -1
  97. package/dist/lib/utils/version.js.map +1 -0
  98. package/dist/meshopt/meshopt-decoder.js +1 -0
  99. package/dist/meshopt/meshopt-decoder.js.map +1 -0
  100. package/dist/webp/webp.js +1 -0
  101. package/dist/webp/webp.js.map +1 -0
  102. package/package.json +7 -7
  103. package/src/glb-loader.ts +10 -8
  104. package/src/gltf-loader.ts +8 -12
  105. package/src/lib/api/post-process-gltf.ts +3 -2
  106. package/src/lib/extensions/EXT_structural_metadata.ts +2 -1
  107. package/src/lib/extensions/KHR_texture_transform.ts +41 -17
  108. package/src/lib/extensions/utils/3d-tiles-utils.ts +2 -1
  109. package/src/lib/gltf-utils/resolve-url.ts +19 -4
  110. package/src/lib/parsers/parse-gltf.ts +16 -13
package/dist/dist.dev.js CHANGED
@@ -105,6 +105,9 @@ var __exports__ = (() => {
105
105
  var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
106
106
  var nodeVersion = matches && parseFloat(matches[1]) || 0;
107
107
 
108
+ // ../loader-utils/src/lib/javascript-utils/is-type.ts
109
+ var isSharedArrayBuffer = (value) => typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
110
+
108
111
  // ../loader-utils/src/lib/module-utils/js-module-utils.ts
109
112
  function registerJSModules(modules) {
110
113
  globalThis.loaders ||= {};
@@ -120,14 +123,16 @@ var __exports__ = (() => {
120
123
  var NPM_TAG = "beta";
121
124
 
122
125
  // ../worker-utils/src/lib/env-utils/version.ts
126
+ var warningIssued = false;
123
127
  function getVersion() {
124
128
  if (!globalThis._loadersgl_?.version) {
125
129
  globalThis._loadersgl_ = globalThis._loadersgl_ || {};
126
- if (typeof __VERSION__ === "undefined") {
130
+ if (typeof __VERSION__ === "undefined" && !warningIssued) {
127
131
  console.warn(
128
132
  "loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN."
129
133
  );
130
134
  globalThis._loadersgl_.version = NPM_TAG;
135
+ warningIssued = true;
131
136
  } else {
132
137
  globalThis._loadersgl_.version = __VERSION__;
133
138
  }
@@ -165,6 +170,16 @@ var __exports__ = (() => {
165
170
 
166
171
  // ../worker-utils/src/lib/library-utils/library-utils.ts
167
172
  var loadLibraryPromises = {};
173
+ function extractLoadLibraryOptions(options = {}) {
174
+ const useLocalLibraries = options.useLocalLibraries ?? options.core?.useLocalLibraries;
175
+ const CDN = options.CDN ?? options.core?.CDN;
176
+ const modules = options.modules;
177
+ return {
178
+ ...useLocalLibraries !== void 0 ? { useLocalLibraries } : {},
179
+ ...CDN !== void 0 ? { CDN } : {},
180
+ ...modules !== void 0 ? { modules } : {}
181
+ };
182
+ }
168
183
  async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
169
184
  if (moduleName) {
170
185
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
@@ -174,6 +189,9 @@ var __exports__ = (() => {
174
189
  return await loadLibraryPromises[libraryUrl];
175
190
  }
176
191
  function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
192
+ if (options?.core) {
193
+ throw new Error("loadLibrary: options.core must be pre-normalized");
194
+ }
177
195
  if (!options.useLocalLibraries && library.startsWith("http")) {
178
196
  return library;
179
197
  }
@@ -199,10 +217,20 @@ var __exports__ = (() => {
199
217
  return await loadAsArrayBuffer(libraryUrl);
200
218
  }
201
219
  if (!isBrowser2) {
220
+ const { requireFromFile } = globalThis.loaders || {};
202
221
  try {
203
- const { requireFromFile } = globalThis.loaders || {};
204
- return await requireFromFile?.(libraryUrl);
222
+ const result = await requireFromFile?.(libraryUrl);
223
+ if (result || !libraryUrl.includes("/dist/libs/")) {
224
+ return result;
225
+ }
226
+ return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
205
227
  } catch (error) {
228
+ if (libraryUrl.includes("/dist/libs/")) {
229
+ try {
230
+ return await requireFromFile?.(libraryUrl.replace("/dist/libs/", "/src/libs/"));
231
+ } catch {
232
+ }
233
+ }
206
234
  console.error(error);
207
235
  return null;
208
236
  }
@@ -238,7 +266,14 @@ var __exports__ = (() => {
238
266
  const response = await fetch(url);
239
267
  return await response.arrayBuffer();
240
268
  }
241
- return await readFileAsArrayBuffer(url);
269
+ try {
270
+ return await readFileAsArrayBuffer(url);
271
+ } catch {
272
+ if (url.includes("/dist/libs/")) {
273
+ return await readFileAsArrayBuffer(url.replace("/dist/libs/", "/src/libs/"));
274
+ }
275
+ throw new Error(`Failed to load ArrayBuffer from ${url}`);
276
+ }
242
277
  }
243
278
  async function loadAsText(url) {
244
279
  const { readFileAsText } = globalThis.loaders || {};
@@ -246,7 +281,14 @@ var __exports__ = (() => {
246
281
  const response = await fetch(url);
247
282
  return await response.text();
248
283
  }
249
- return await readFileAsText(url);
284
+ try {
285
+ return await readFileAsText(url);
286
+ } catch {
287
+ if (url.includes("/dist/libs/")) {
288
+ return await readFileAsText(url.replace("/dist/libs/", "/src/libs/"));
289
+ }
290
+ throw new Error(`Failed to load text from ${url}`);
291
+ }
250
292
  }
251
293
 
252
294
  // ../loader-utils/src/lib/binary-utils/get-first-characters.ts
@@ -334,6 +376,27 @@ var __exports__ = (() => {
334
376
  return byteOffset;
335
377
  }
336
378
 
379
+ // ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
380
+ function ensureArrayBuffer(bufferSource) {
381
+ if (bufferSource instanceof ArrayBuffer) {
382
+ return bufferSource;
383
+ }
384
+ if (isSharedArrayBuffer(bufferSource)) {
385
+ return copyToArrayBuffer(bufferSource);
386
+ }
387
+ const { buffer, byteOffset, byteLength } = bufferSource;
388
+ if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
389
+ return buffer;
390
+ }
391
+ return copyToArrayBuffer(buffer, byteOffset, byteLength);
392
+ }
393
+ function copyToArrayBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
394
+ const view = new Uint8Array(buffer, byteOffset, byteLength);
395
+ const copy = new Uint8Array(view.length);
396
+ copy.set(view);
397
+ return copy.buffer;
398
+ }
399
+
337
400
  // ../images/src/lib/category-api/image-type.ts
338
401
  var parseImageNode = globalThis.loaders?.parseImageNode;
339
402
  var IMAGE_SUPPORTED = typeof Image !== "undefined";
@@ -470,7 +533,6 @@ var __exports__ = (() => {
470
533
  }
471
534
 
472
535
  // ../images/src/lib/parsers/parse-to-image-bitmap.ts
473
- var EMPTY_OBJECT = {};
474
536
  var imagebitmapOptionsSupported = true;
475
537
  async function parseToImageBitmap(arrayBuffer, options, url) {
476
538
  let blob;
@@ -498,8 +560,13 @@ var __exports__ = (() => {
498
560
  return await createImageBitmap(blob);
499
561
  }
500
562
  function isEmptyObject(object) {
501
- for (const key in object || EMPTY_OBJECT) {
502
- return false;
563
+ if (!object) {
564
+ return true;
565
+ }
566
+ for (const key in object) {
567
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
568
+ return false;
569
+ }
503
570
  }
504
571
  return true;
505
572
  }
@@ -1520,7 +1587,7 @@ var __exports__ = (() => {
1520
1587
  buffer = bufferArray.slice(offset, offset + byteLength).buffer;
1521
1588
  offset = 0;
1522
1589
  }
1523
- return new ArrayType(buffer, offset, length);
1590
+ return new ArrayType(ensureArrayBuffer(buffer), offset, length);
1524
1591
  }
1525
1592
  function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
1526
1593
  const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
@@ -2278,7 +2345,7 @@ var __exports__ = (() => {
2278
2345
  }
2279
2346
  function createBufferView(typedArray, scenegraph) {
2280
2347
  scenegraph.gltf.buffers.push({
2281
- arrayBuffer: typedArray.buffer,
2348
+ arrayBuffer: ensureArrayBuffer(typedArray.buffer),
2282
2349
  byteOffset: typedArray.byteOffset,
2283
2350
  byteLength: typedArray.byteLength
2284
2351
  });
@@ -2616,104 +2683,117 @@ var __exports__ = (() => {
2616
2683
  }
2617
2684
 
2618
2685
  // ../textures/src/lib/gl-extensions.ts
2619
- var GL_EXTENSIONS_CONSTANTS = {
2620
- // WEBGL_compressed_texture_s3tc
2621
- COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
2622
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
2623
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
2624
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
2625
- // WEBGL_compressed_texture_es3
2626
- COMPRESSED_R11_EAC: 37488,
2627
- COMPRESSED_SIGNED_R11_EAC: 37489,
2628
- COMPRESSED_RG11_EAC: 37490,
2629
- COMPRESSED_SIGNED_RG11_EAC: 37491,
2630
- COMPRESSED_RGB8_ETC2: 37492,
2631
- COMPRESSED_RGBA8_ETC2_EAC: 37493,
2632
- COMPRESSED_SRGB8_ETC2: 37494,
2633
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
2634
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
2635
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
2636
- // WEBGL_compressed_texture_pvrtc
2637
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
2638
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
2639
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
2640
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
2641
- // WEBGL_compressed_texture_etc1
2642
- COMPRESSED_RGB_ETC1_WEBGL: 36196,
2643
- // WEBGL_compressed_texture_atc
2644
- COMPRESSED_RGB_ATC_WEBGL: 35986,
2645
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
2646
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
2647
- // WEBGL_compressed_texture_astc
2648
- COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
2649
- COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
2650
- COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
2651
- COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
2652
- COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
2653
- COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
2654
- COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
2655
- COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
2656
- COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
2657
- COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
2658
- COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
2659
- COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
2660
- COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
2661
- COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
2662
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
2663
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
2664
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
2665
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
2666
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
2667
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
2668
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
2669
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
2670
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
2671
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
2672
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
2673
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
2674
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
2675
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
2676
- // EXT_texture_compression_rgtc
2677
- COMPRESSED_RED_RGTC1_EXT: 36283,
2678
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
2679
- COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
2680
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
2681
- // WEBGL_compressed_texture_s3tc_srgb
2682
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
2683
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
2684
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
2685
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
2686
- };
2686
+ var GL_RGBA4 = 32854;
2687
+ var GL_RGBA8 = 32856;
2688
+ var GL_RGB565 = 36194;
2689
+ var GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 33776;
2690
+ var GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779;
2691
+ var GL_COMPRESSED_RGBA8_ETC2_EAC = 37493;
2692
+ var GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 35840;
2693
+ var GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 35842;
2694
+ var GL_COMPRESSED_RGB_ETC1_WEBGL = 36196;
2695
+ var GL_COMPRESSED_RGB_ATC_WEBGL = 35986;
2696
+ var GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 34798;
2697
+ var GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 37808;
2698
+ var GL_COMPRESSED_RED_RGTC1_EXT = 36283;
2699
+ var GL_COMPRESSED_RED_GREEN_RGTC2_EXT = 36285;
2700
+ var GL_COMPRESSED_RGBA_BPTC_UNORM_EXT = 36492;
2687
2701
 
2688
- // ../textures/src/lib/utils/texture-formats.ts
2702
+ // ../textures/src/lib/utils/detect-supported-texture-formats.ts
2689
2703
  var BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
2690
- var WEBGL_EXTENSIONS = {
2704
+ var WEBGL_TEXTURE_FORMATS = {
2691
2705
  /* eslint-disable camelcase */
2692
- WEBGL_compressed_texture_s3tc: "dxt",
2693
- WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
2694
- WEBGL_compressed_texture_etc1: "etc1",
2695
- WEBGL_compressed_texture_etc: "etc2",
2696
- WEBGL_compressed_texture_pvrtc: "pvrtc",
2697
- WEBGL_compressed_texture_atc: "atc",
2698
- WEBGL_compressed_texture_astc: "astc",
2699
- EXT_texture_compression_rgtc: "rgtc"
2706
+ WEBGL_compressed_texture_s3tc: [
2707
+ "bc1-rgb-unorm-webgl",
2708
+ "bc1-rgba-unorm",
2709
+ "bc2-rgba-unorm",
2710
+ "bc3-rgba-unorm"
2711
+ ],
2712
+ WEBGL_compressed_texture_s3tc_srgb: [
2713
+ "bc1-rgb-unorm-srgb-webgl",
2714
+ "bc1-rgba-unorm-srgb",
2715
+ "bc2-rgba-unorm-srgb",
2716
+ "bc3-rgba-unorm-srgb"
2717
+ ],
2718
+ EXT_texture_compression_rgtc: ["bc4-r-unorm", "bc4-r-snorm", "bc5-rg-unorm", "bc5-rg-snorm"],
2719
+ EXT_texture_compression_bptc: [
2720
+ "bc6h-rgb-ufloat",
2721
+ "bc6h-rgb-float",
2722
+ "bc7-rgba-unorm",
2723
+ "bc7-rgba-unorm-srgb"
2724
+ ],
2725
+ WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
2726
+ WEBGL_compressed_texture_etc: [
2727
+ "etc2-rgb8unorm",
2728
+ "etc2-rgb8unorm-srgb",
2729
+ "etc2-rgb8a1unorm",
2730
+ "etc2-rgb8a1unorm-srgb",
2731
+ "etc2-rgba8unorm",
2732
+ "etc2-rgba8unorm-srgb",
2733
+ "eac-r11unorm",
2734
+ "eac-r11snorm",
2735
+ "eac-rg11unorm",
2736
+ "eac-rg11snorm"
2737
+ ],
2738
+ WEBGL_compressed_texture_pvrtc: [
2739
+ "pvrtc-rgb4unorm-webgl",
2740
+ "pvrtc-rgba4unorm-webgl",
2741
+ "pvrtc-rgb2unorm-webgl",
2742
+ "pvrtc-rgba2unorm-webgl"
2743
+ ],
2744
+ WEBGL_compressed_texture_atc: [
2745
+ "atc-rgb-unorm-webgl",
2746
+ "atc-rgba-unorm-webgl",
2747
+ "atc-rgbai-unorm-webgl"
2748
+ ],
2749
+ WEBGL_compressed_texture_astc: [
2750
+ "astc-4x4-unorm",
2751
+ "astc-4x4-unorm-srgb",
2752
+ "astc-5x4-unorm",
2753
+ "astc-5x4-unorm-srgb",
2754
+ "astc-5x5-unorm",
2755
+ "astc-5x5-unorm-srgb",
2756
+ "astc-6x5-unorm",
2757
+ "astc-6x5-unorm-srgb",
2758
+ "astc-6x6-unorm",
2759
+ "astc-6x6-unorm-srgb",
2760
+ "astc-8x5-unorm",
2761
+ "astc-8x5-unorm-srgb",
2762
+ "astc-8x6-unorm",
2763
+ "astc-8x6-unorm-srgb",
2764
+ "astc-8x8-unorm",
2765
+ "astc-8x8-unorm-srgb",
2766
+ "astc-10x5-unorm",
2767
+ "astc-10x5-unorm-srgb",
2768
+ "astc-10x6-unorm",
2769
+ "astc-10x6-unorm-srgb",
2770
+ "astc-10x8-unorm",
2771
+ "astc-10x8-unorm-srgb",
2772
+ "astc-10x10-unorm",
2773
+ "astc-10x10-unorm-srgb",
2774
+ "astc-12x10-unorm",
2775
+ "astc-12x10-unorm-srgb",
2776
+ "astc-12x12-unorm",
2777
+ "astc-12x12-unorm-srgb"
2778
+ ]
2700
2779
  /* eslint-enable camelcase */
2701
2780
  };
2702
- var formats = null;
2703
- function getSupportedGPUTextureFormats(gl) {
2704
- if (!formats) {
2781
+ var textureFormats = null;
2782
+ function detectSupportedTextureFormats(gl) {
2783
+ if (!textureFormats) {
2705
2784
  gl = gl || getWebGLContext() || void 0;
2706
- formats = /* @__PURE__ */ new Set();
2785
+ textureFormats = /* @__PURE__ */ new Set();
2707
2786
  for (const prefix of BROWSER_PREFIXES) {
2708
- for (const extension in WEBGL_EXTENSIONS) {
2787
+ for (const extension in WEBGL_TEXTURE_FORMATS) {
2709
2788
  if (gl && gl.getExtension(`${prefix}${extension}`)) {
2710
- const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
2711
- formats.add(gpuTextureFormat);
2789
+ for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
2790
+ textureFormats.add(textureFormat);
2791
+ }
2712
2792
  }
2713
2793
  }
2714
2794
  }
2715
2795
  }
2716
- return formats;
2796
+ return textureFormats;
2717
2797
  }
2718
2798
  function getWebGLContext() {
2719
2799
  try {
@@ -2758,73 +2838,154 @@ var __exports__ = (() => {
2758
2838
  }
2759
2839
 
2760
2840
  // ../textures/src/lib/parsers/parse-basis.ts
2761
- var OutputFormat = {
2841
+ var basisTranscodingLock = Promise.resolve();
2842
+ var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
2762
2843
  etc1: {
2763
2844
  basisFormat: 0,
2764
2845
  compressed: true,
2765
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
2846
+ format: GL_COMPRESSED_RGB_ETC1_WEBGL,
2847
+ textureFormat: "etc1-rgb-unorm-webgl"
2848
+ },
2849
+ etc2: {
2850
+ basisFormat: 1,
2851
+ compressed: true,
2852
+ format: GL_COMPRESSED_RGBA8_ETC2_EAC,
2853
+ textureFormat: "etc2-rgba8unorm"
2766
2854
  },
2767
- etc2: { basisFormat: 1, compressed: true },
2768
2855
  bc1: {
2769
2856
  basisFormat: 2,
2770
2857
  compressed: true,
2771
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
2858
+ format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2859
+ textureFormat: "bc1-rgb-unorm-webgl"
2772
2860
  },
2773
2861
  bc3: {
2774
2862
  basisFormat: 3,
2775
2863
  compressed: true,
2776
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
2864
+ format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
2865
+ textureFormat: "bc3-rgba-unorm"
2866
+ },
2867
+ bc4: {
2868
+ basisFormat: 4,
2869
+ compressed: true,
2870
+ format: GL_COMPRESSED_RED_RGTC1_EXT,
2871
+ textureFormat: "bc4-r-unorm"
2872
+ },
2873
+ bc5: {
2874
+ basisFormat: 5,
2875
+ compressed: true,
2876
+ format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
2877
+ textureFormat: "bc5-rg-unorm"
2878
+ },
2879
+ "bc7-m6-opaque-only": {
2880
+ basisFormat: 6,
2881
+ compressed: true,
2882
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
2883
+ textureFormat: "bc7-rgba-unorm"
2884
+ },
2885
+ "bc7-m5": {
2886
+ basisFormat: 7,
2887
+ compressed: true,
2888
+ format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
2889
+ textureFormat: "bc7-rgba-unorm"
2777
2890
  },
2778
- bc4: { basisFormat: 4, compressed: true },
2779
- bc5: { basisFormat: 5, compressed: true },
2780
- "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
2781
- "bc7-m5": { basisFormat: 7, compressed: true },
2782
2891
  "pvrtc1-4-rgb": {
2783
2892
  basisFormat: 8,
2784
2893
  compressed: true,
2785
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
2894
+ format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
2895
+ textureFormat: "pvrtc-rgb4unorm-webgl"
2786
2896
  },
2787
2897
  "pvrtc1-4-rgba": {
2788
2898
  basisFormat: 9,
2789
2899
  compressed: true,
2790
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
2900
+ format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
2901
+ textureFormat: "pvrtc-rgba4unorm-webgl"
2791
2902
  },
2792
2903
  "astc-4x4": {
2793
2904
  basisFormat: 10,
2794
2905
  compressed: true,
2795
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
2906
+ format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
2907
+ textureFormat: "astc-4x4-unorm"
2796
2908
  },
2797
- "atc-rgb": { basisFormat: 11, compressed: true },
2798
- "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
2799
- rgba32: { basisFormat: 13, compressed: false },
2800
- rgb565: { basisFormat: 14, compressed: false },
2801
- bgr565: { basisFormat: 15, compressed: false },
2802
- rgba4444: { basisFormat: 16, compressed: false }
2909
+ "atc-rgb": {
2910
+ basisFormat: 11,
2911
+ compressed: true,
2912
+ format: GL_COMPRESSED_RGB_ATC_WEBGL,
2913
+ textureFormat: "atc-rgb-unorm-webgl"
2914
+ },
2915
+ "atc-rgba-interpolated-alpha": {
2916
+ basisFormat: 12,
2917
+ compressed: true,
2918
+ format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
2919
+ textureFormat: "atc-rgbai-unorm-webgl"
2920
+ },
2921
+ rgba32: {
2922
+ basisFormat: 13,
2923
+ compressed: false,
2924
+ format: GL_RGBA8,
2925
+ textureFormat: "rgba8unorm"
2926
+ },
2927
+ rgb565: {
2928
+ basisFormat: 14,
2929
+ compressed: false,
2930
+ format: GL_RGB565,
2931
+ textureFormat: "rgb565unorm-webgl"
2932
+ },
2933
+ bgr565: {
2934
+ basisFormat: 15,
2935
+ compressed: false,
2936
+ format: GL_RGB565,
2937
+ textureFormat: "rgb565unorm-webgl"
2938
+ },
2939
+ rgba4444: {
2940
+ basisFormat: 16,
2941
+ compressed: false,
2942
+ format: GL_RGBA4,
2943
+ textureFormat: "rgba4unorm-webgl"
2944
+ }
2803
2945
  };
2804
- async function parseBasis(data, options) {
2805
- if (options.basis.containerFormat === "auto") {
2806
- if (isKTX(data)) {
2807
- const fileConstructors = await loadBasisEncoderModule(options);
2808
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2809
- }
2810
- const { BasisFile } = await loadBasisTranscoderModule(options);
2811
- return parseBasisFile(BasisFile, data, options);
2812
- }
2813
- switch (options.basis.module) {
2814
- case "encoder":
2815
- const fileConstructors = await loadBasisEncoderModule(options);
2816
- switch (options.basis.containerFormat) {
2817
- case "ktx2":
2818
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2819
- case "basis":
2820
- default:
2821
- return parseBasisFile(fileConstructors.BasisFile, data, options);
2946
+ var BASIS_FORMATS = Object.freeze(
2947
+ Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS)
2948
+ );
2949
+ async function withBasisTranscodingLock(transcode) {
2950
+ const previousLock = basisTranscodingLock;
2951
+ let releaseLock;
2952
+ basisTranscodingLock = new Promise((resolve) => {
2953
+ releaseLock = resolve;
2954
+ });
2955
+ await previousLock;
2956
+ try {
2957
+ return await transcode();
2958
+ } finally {
2959
+ releaseLock();
2960
+ }
2961
+ }
2962
+ async function parseBasis(data, options = {}) {
2963
+ const loadLibraryOptions = extractLoadLibraryOptions(options);
2964
+ return await withBasisTranscodingLock(async () => {
2965
+ if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
2966
+ if (isKTX(data)) {
2967
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2968
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
2822
2969
  }
2823
- case "transcoder":
2824
- default:
2825
- const { BasisFile } = await loadBasisTranscoderModule(options);
2970
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2826
2971
  return parseBasisFile(BasisFile, data, options);
2827
- }
2972
+ }
2973
+ switch (options.basis.module) {
2974
+ case "encoder":
2975
+ const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2976
+ switch (options.basis.containerFormat) {
2977
+ case "ktx2":
2978
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
2979
+ case "basis":
2980
+ default:
2981
+ return parseBasisFile(fileConstructors.BasisFile, data, options);
2982
+ }
2983
+ case "transcoder":
2984
+ default:
2985
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2986
+ return parseBasisFile(BasisFile, data, options);
2987
+ }
2988
+ });
2828
2989
  }
2829
2990
  function parseBasisFile(BasisFile, data, options) {
2830
2991
  const basisFile = new BasisFile(new Uint8Array(data));
@@ -2854,7 +3015,7 @@ var __exports__ = (() => {
2854
3015
  const hasAlpha = basisFile.getHasAlpha(
2855
3016
  /* imageIndex, levelIndex */
2856
3017
  );
2857
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
3018
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, hasAlpha);
2858
3019
  const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
2859
3020
  const decodedData = new Uint8Array(decodedSize);
2860
3021
  if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
@@ -2862,11 +3023,13 @@ var __exports__ = (() => {
2862
3023
  }
2863
3024
  return {
2864
3025
  // standard loaders.gl image category payload
3026
+ shape: "texture-level",
2865
3027
  width,
2866
3028
  height,
2867
3029
  data: decodedData,
2868
3030
  compressed,
2869
- format,
3031
+ ...format !== void 0 ? { format } : {},
3032
+ ...textureFormat !== void 0 ? { textureFormat } : {},
2870
3033
  // Additional fields
2871
3034
  // Add levelSize field.
2872
3035
  hasAlpha
@@ -2891,7 +3054,7 @@ var __exports__ = (() => {
2891
3054
  }
2892
3055
  function transcodeKTX2Image(ktx2File, levelIndex, options) {
2893
3056
  const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
2894
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
3057
+ const { compressed, format, basisFormat, textureFormat } = getBasisOptions(options, alphaFlag);
2895
3058
  const decodedSize = ktx2File.getImageTranscodedSizeInBytes(
2896
3059
  levelIndex,
2897
3060
  0,
@@ -2914,48 +3077,98 @@ var __exports__ = (() => {
2914
3077
  }
2915
3078
  return {
2916
3079
  // standard loaders.gl image category payload
3080
+ shape: "texture-level",
2917
3081
  width,
2918
3082
  height,
2919
3083
  data: decodedData,
2920
3084
  compressed,
3085
+ ...format !== void 0 ? { format } : {},
3086
+ ...textureFormat !== void 0 ? { textureFormat } : {},
2921
3087
  // Additional fields
2922
3088
  levelSize: decodedSize,
2923
- hasAlpha: alphaFlag,
2924
- format
3089
+ hasAlpha: alphaFlag
2925
3090
  };
2926
3091
  }
2927
3092
  function getBasisOptions(options, hasAlpha) {
2928
- let format = options && options.basis && options.basis.format;
3093
+ let format = options.basis?.format || "auto";
2929
3094
  if (format === "auto") {
2930
- format = selectSupportedBasisFormat();
3095
+ format = options.basis?.supportedTextureFormats ? selectSupportedBasisFormat(options.basis.supportedTextureFormats) : selectSupportedBasisFormat();
2931
3096
  }
2932
3097
  if (typeof format === "object") {
2933
3098
  format = hasAlpha ? format.alpha : format.noAlpha;
2934
3099
  }
2935
- format = format.toLowerCase();
2936
- return OutputFormat[format];
3100
+ const normalizedFormat = format.toLowerCase();
3101
+ const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
3102
+ if (!basisOutputOptions) {
3103
+ throw new Error(`Unknown Basis format ${format}`);
3104
+ }
3105
+ return basisOutputOptions;
2937
3106
  }
2938
- function selectSupportedBasisFormat() {
2939
- const supportedFormats = getSupportedGPUTextureFormats();
2940
- if (supportedFormats.has("astc")) {
3107
+ function selectSupportedBasisFormat(supportedTextureFormats = detectSupportedTextureFormats()) {
3108
+ const textureFormats2 = new Set(supportedTextureFormats);
3109
+ if (hasSupportedTextureFormat(textureFormats2, ["astc-4x4-unorm", "astc-4x4-unorm-srgb"])) {
2941
3110
  return "astc-4x4";
2942
- } else if (supportedFormats.has("dxt")) {
3111
+ } else if (hasSupportedTextureFormat(textureFormats2, ["bc7-rgba-unorm", "bc7-rgba-unorm-srgb"])) {
3112
+ return {
3113
+ alpha: "bc7-m5",
3114
+ noAlpha: "bc7-m6-opaque-only"
3115
+ };
3116
+ } else if (hasSupportedTextureFormat(textureFormats2, [
3117
+ "bc1-rgb-unorm-webgl",
3118
+ "bc1-rgb-unorm-srgb-webgl",
3119
+ "bc1-rgba-unorm",
3120
+ "bc1-rgba-unorm-srgb",
3121
+ "bc2-rgba-unorm",
3122
+ "bc2-rgba-unorm-srgb",
3123
+ "bc3-rgba-unorm",
3124
+ "bc3-rgba-unorm-srgb"
3125
+ ])) {
2943
3126
  return {
2944
3127
  alpha: "bc3",
2945
3128
  noAlpha: "bc1"
2946
3129
  };
2947
- } else if (supportedFormats.has("pvrtc")) {
3130
+ } else if (hasSupportedTextureFormat(textureFormats2, [
3131
+ "pvrtc-rgb4unorm-webgl",
3132
+ "pvrtc-rgba4unorm-webgl",
3133
+ "pvrtc-rgb2unorm-webgl",
3134
+ "pvrtc-rgba2unorm-webgl"
3135
+ ])) {
2948
3136
  return {
2949
3137
  alpha: "pvrtc1-4-rgba",
2950
3138
  noAlpha: "pvrtc1-4-rgb"
2951
3139
  };
2952
- } else if (supportedFormats.has("etc1")) {
2953
- return "etc1";
2954
- } else if (supportedFormats.has("etc2")) {
3140
+ } else if (hasSupportedTextureFormat(textureFormats2, [
3141
+ "etc2-rgb8unorm",
3142
+ "etc2-rgb8unorm-srgb",
3143
+ "etc2-rgb8a1unorm",
3144
+ "etc2-rgb8a1unorm-srgb",
3145
+ "etc2-rgba8unorm",
3146
+ "etc2-rgba8unorm-srgb",
3147
+ "eac-r11unorm",
3148
+ "eac-r11snorm",
3149
+ "eac-rg11unorm",
3150
+ "eac-rg11snorm"
3151
+ ])) {
2955
3152
  return "etc2";
3153
+ } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
3154
+ return "etc1";
3155
+ } else if (hasSupportedTextureFormat(textureFormats2, [
3156
+ "atc-rgb-unorm-webgl",
3157
+ "atc-rgba-unorm-webgl",
3158
+ "atc-rgbai-unorm-webgl"
3159
+ ])) {
3160
+ return {
3161
+ alpha: "atc-rgba-interpolated-alpha",
3162
+ noAlpha: "atc-rgb"
3163
+ };
2956
3164
  }
2957
3165
  return "rgb565";
2958
3166
  }
3167
+ function hasSupportedTextureFormat(supportedTextureFormats, candidateTextureFormats) {
3168
+ return candidateTextureFormats.some(
3169
+ (textureFormat) => supportedTextureFormats.has(textureFormat)
3170
+ );
3171
+ }
2959
3172
 
2960
3173
  // ../textures/src/basis-loader.ts
2961
3174
  var BasisWorkerLoader = {
@@ -2973,7 +3186,6 @@ var __exports__ = (() => {
2973
3186
  options: {
2974
3187
  basis: {
2975
3188
  format: "auto",
2976
- libraryPath: "libs/",
2977
3189
  containerFormat: "auto",
2978
3190
  module: "transcoder"
2979
3191
  }
@@ -3095,16 +3307,26 @@ var __exports__ = (() => {
3095
3307
  }
3096
3308
 
3097
3309
  // src/lib/gltf-utils/resolve-url.ts
3098
- function resolveUrl(url, options) {
3310
+ function resolveUrl(url, options, context) {
3099
3311
  const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
3100
3312
  if (absolute) {
3101
3313
  return url;
3102
3314
  }
3103
- const baseUrl = options.baseUri || options.uri;
3315
+ const baseUrl = context?.baseUrl || getResolveBaseUrl(options?.core?.baseUrl);
3104
3316
  if (!baseUrl) {
3105
- throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
3317
+ throw new Error(`'baseUrl' must be provided to resolve relative url ${url}`);
3106
3318
  }
3107
- return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url;
3319
+ return baseUrl.endsWith("/") ? `${baseUrl}${url}` : `${baseUrl}/${url}`;
3320
+ }
3321
+ function getResolveBaseUrl(baseUrl) {
3322
+ if (!baseUrl) {
3323
+ return void 0;
3324
+ }
3325
+ if (baseUrl.endsWith("/")) {
3326
+ return baseUrl;
3327
+ }
3328
+ const slashIndex = baseUrl.lastIndexOf("/");
3329
+ return slashIndex >= 0 ? baseUrl.slice(0, slashIndex + 1) : "";
3108
3330
  }
3109
3331
 
3110
3332
  // src/lib/extensions/EXT_meshopt_compression.ts
@@ -3439,21 +3661,32 @@ var __exports__ = (() => {
3439
3661
  [DRACO_EXTERNAL_LIBRARIES.ENCODER]: `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/${DRACO_EXTERNAL_LIBRARIES.ENCODER}`
3440
3662
  };
3441
3663
  var loadDecoderPromise;
3442
- async function loadDracoDecoderModule(options) {
3664
+ async function loadDracoDecoderModule(options = {}, type) {
3443
3665
  const modules = options.modules || {};
3444
3666
  if (modules.draco3d) {
3445
3667
  loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => {
3446
3668
  return { draco };
3447
3669
  });
3448
3670
  } else {
3449
- loadDecoderPromise ||= loadDracoDecoder(options);
3671
+ loadDecoderPromise ||= loadDracoDecoder(options, type);
3450
3672
  }
3451
3673
  return await loadDecoderPromise;
3452
3674
  }
3453
- async function loadDracoDecoder(options) {
3675
+ function getLibraryExport(library, exportName) {
3676
+ if (library && typeof library === "object") {
3677
+ if (library.default) {
3678
+ return library.default;
3679
+ }
3680
+ if (library[exportName]) {
3681
+ return library[exportName];
3682
+ }
3683
+ }
3684
+ return library;
3685
+ }
3686
+ async function loadDracoDecoder(options, type) {
3454
3687
  let DracoDecoderModule;
3455
3688
  let wasmBinary;
3456
- switch (options.draco && options.draco.decoderType) {
3689
+ switch (type) {
3457
3690
  case "js":
3458
3691
  DracoDecoderModule = await loadLibrary(
3459
3692
  DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER],
@@ -3464,25 +3697,52 @@ var __exports__ = (() => {
3464
3697
  break;
3465
3698
  case "wasm":
3466
3699
  default:
3467
- [DracoDecoderModule, wasmBinary] = await Promise.all([
3468
- await loadLibrary(
3469
- DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER],
3470
- "draco",
3471
- options,
3472
- DRACO_EXTERNAL_LIBRARIES.DECODER
3473
- ),
3474
- await loadLibrary(
3475
- DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM],
3476
- "draco",
3477
- options,
3478
- DRACO_EXTERNAL_LIBRARIES.DECODER_WASM
3479
- )
3480
- ]);
3700
+ try {
3701
+ [DracoDecoderModule, wasmBinary] = await Promise.all([
3702
+ await loadLibrary(
3703
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER],
3704
+ "draco",
3705
+ options,
3706
+ DRACO_EXTERNAL_LIBRARIES.DECODER
3707
+ ),
3708
+ await loadLibrary(
3709
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM],
3710
+ "draco",
3711
+ options,
3712
+ DRACO_EXTERNAL_LIBRARIES.DECODER_WASM
3713
+ )
3714
+ ]);
3715
+ } catch {
3716
+ DracoDecoderModule = null;
3717
+ wasmBinary = null;
3718
+ }
3481
3719
  }
3720
+ DracoDecoderModule = getLibraryExport(DracoDecoderModule, "DracoDecoderModule");
3482
3721
  DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
3722
+ if (!DracoDecoderModule && !isBrowser2) {
3723
+ [DracoDecoderModule, wasmBinary] = await Promise.all([
3724
+ await loadLibrary(
3725
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER],
3726
+ "draco",
3727
+ { ...options, useLocalLibraries: true },
3728
+ DRACO_EXTERNAL_LIBRARIES.DECODER
3729
+ ),
3730
+ await loadLibrary(
3731
+ DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM],
3732
+ "draco",
3733
+ { ...options, useLocalLibraries: true },
3734
+ DRACO_EXTERNAL_LIBRARIES.DECODER_WASM
3735
+ )
3736
+ ]);
3737
+ DracoDecoderModule = getLibraryExport(DracoDecoderModule, "DracoDecoderModule");
3738
+ DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
3739
+ }
3483
3740
  return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
3484
3741
  }
3485
3742
  function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
3743
+ if (typeof DracoDecoderModule !== "function") {
3744
+ throw new Error("DracoDecoderModule could not be loaded");
3745
+ }
3486
3746
  const options = {};
3487
3747
  if (wasmBinary) {
3488
3748
  options.wasmBinary = wasmBinary;
@@ -4091,7 +4351,6 @@ var __exports__ = (() => {
4091
4351
  draco: {
4092
4352
  decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
4093
4353
  // 'js' for IE11
4094
- libraryPath: "libs/",
4095
4354
  extraAttributes: {},
4096
4355
  attributeNameEntry: void 0
4097
4356
  }
@@ -4102,7 +4361,10 @@ var __exports__ = (() => {
4102
4361
  parse
4103
4362
  };
4104
4363
  async function parse(arrayBuffer, options) {
4105
- const { draco } = await loadDracoDecoderModule(options);
4364
+ const { draco } = await loadDracoDecoderModule(
4365
+ extractLoadLibraryOptions(options),
4366
+ options?.draco?.decoderType || "wasm"
4367
+ );
4106
4368
  const dracoParser = new DracoParser(draco);
4107
4369
  try {
4108
4370
  return dracoParser.parseSync(arrayBuffer, options?.draco);
@@ -5566,7 +5828,7 @@ var __exports__ = (() => {
5566
5828
  const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
5567
5829
  if (Number.isFinite(texCoordAccessor)) {
5568
5830
  const accessor = gltfData.json.accessors?.[texCoordAccessor];
5569
- if (accessor && accessor.bufferView) {
5831
+ if (accessor && accessor.bufferView !== void 0) {
5570
5832
  const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
5571
5833
  if (bufferView) {
5572
5834
  const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
@@ -5583,7 +5845,7 @@ var __exports__ = (() => {
5583
5845
  result.set([scratchVector[0], scratchVector[1]], i * components);
5584
5846
  }
5585
5847
  if (originalTexCoord === texCoord) {
5586
- updateGltf(accessor, bufferView, gltfData.buffers, result);
5848
+ updateGltf(accessor, gltfData, result, accessor.bufferView);
5587
5849
  } else {
5588
5850
  createAttribute(texCoord, accessor, primitive, gltfData, result);
5589
5851
  }
@@ -5591,28 +5853,49 @@ var __exports__ = (() => {
5591
5853
  }
5592
5854
  }
5593
5855
  }
5594
- function updateGltf(accessor, bufferView, buffers, newTexCoordArray) {
5856
+ function updateGltf(accessor, gltfData, newTexCoordArray, originalBufferViewIndex) {
5595
5857
  accessor.componentType = 5126;
5596
- buffers.push({
5597
- arrayBuffer: newTexCoordArray.buffer,
5858
+ accessor.byteOffset = 0;
5859
+ const accessors = gltfData.json.accessors || [];
5860
+ const bufferViewReferenceCount = accessors.reduce((count, currentAccessor) => {
5861
+ return currentAccessor.bufferView === originalBufferViewIndex ? count + 1 : count;
5862
+ }, 0);
5863
+ const shouldCreateNewBufferView = bufferViewReferenceCount > 1;
5864
+ gltfData.buffers.push({
5865
+ arrayBuffer: ensureArrayBuffer(newTexCoordArray.buffer),
5598
5866
  byteOffset: 0,
5599
5867
  byteLength: newTexCoordArray.buffer.byteLength
5600
5868
  });
5601
- bufferView.buffer = buffers.length - 1;
5602
- bufferView.byteLength = newTexCoordArray.buffer.byteLength;
5869
+ const newBufferIndex = gltfData.buffers.length - 1;
5870
+ gltfData.json.bufferViews = gltfData.json.bufferViews || [];
5871
+ if (shouldCreateNewBufferView) {
5872
+ gltfData.json.bufferViews.push({
5873
+ buffer: newBufferIndex,
5874
+ byteLength: newTexCoordArray.buffer.byteLength,
5875
+ byteOffset: 0
5876
+ });
5877
+ accessor.bufferView = gltfData.json.bufferViews.length - 1;
5878
+ return;
5879
+ }
5880
+ const bufferView = gltfData.json.bufferViews[originalBufferViewIndex];
5881
+ if (!bufferView) {
5882
+ return;
5883
+ }
5884
+ bufferView.buffer = newBufferIndex;
5603
5885
  bufferView.byteOffset = 0;
5604
- delete bufferView.byteStride;
5886
+ bufferView.byteLength = newTexCoordArray.buffer.byteLength;
5887
+ if (bufferView.byteStride !== void 0) {
5888
+ delete bufferView.byteStride;
5889
+ }
5605
5890
  }
5606
5891
  function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) {
5607
5892
  gltfData.buffers.push({
5608
- arrayBuffer: newTexCoordArray.buffer,
5893
+ arrayBuffer: ensureArrayBuffer(newTexCoordArray.buffer),
5609
5894
  byteOffset: 0,
5610
5895
  byteLength: newTexCoordArray.buffer.byteLength
5611
5896
  });
5897
+ gltfData.json.bufferViews = gltfData.json.bufferViews || [];
5612
5898
  const bufferViews = gltfData.json.bufferViews;
5613
- if (!bufferViews) {
5614
- return;
5615
- }
5616
5899
  bufferViews.push({
5617
5900
  buffer: gltfData.buffers.length - 1,
5618
5901
  byteLength: newTexCoordArray.buffer.byteLength,
@@ -6088,10 +6371,10 @@ var __exports__ = (() => {
6088
6371
  return gltf;
6089
6372
  }
6090
6373
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
6091
- if (options.uri) {
6092
- gltf.baseUri = options.uri;
6374
+ if (options.core?.baseUrl) {
6375
+ gltf.baseUri = options.core?.baseUrl;
6093
6376
  }
6094
- if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) {
6377
+ if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options.glb)) {
6095
6378
  const textDecoder = new TextDecoder();
6096
6379
  data = textDecoder.decode(data);
6097
6380
  }
@@ -6126,7 +6409,7 @@ var __exports__ = (() => {
6126
6409
  if (buffer.uri) {
6127
6410
  const { fetch: fetch2 } = context;
6128
6411
  assert3(fetch2);
6129
- const uri = resolveUrl(buffer.uri, options);
6412
+ const uri = resolveUrl(buffer.uri, options, context);
6130
6413
  const response = await context?.fetch?.(uri);
6131
6414
  const arrayBuffer = await response?.arrayBuffer?.();
6132
6415
  gltf.buffers[i] = {
@@ -6166,7 +6449,7 @@ var __exports__ = (() => {
6166
6449
  async function loadImage(gltf, image, index, options, context) {
6167
6450
  let arrayBuffer;
6168
6451
  if (image.uri && !image.hasOwnProperty("bufferView")) {
6169
- const uri = resolveUrl(image.uri, options);
6452
+ const uri = resolveUrl(image.uri, options, context);
6170
6453
  const { fetch: fetch2 } = context;
6171
6454
  const response = await fetch2(uri);
6172
6455
  arrayBuffer = await response.arrayBuffer();
@@ -6179,14 +6462,15 @@ var __exports__ = (() => {
6179
6462
  arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength);
6180
6463
  }
6181
6464
  assert3(arrayBuffer, "glTF image has no data");
6465
+ const strictOptions = options;
6466
+ const gltfOptions = {
6467
+ ...strictOptions,
6468
+ core: { ...strictOptions?.core, mimeType: image.mimeType }
6469
+ };
6182
6470
  let parsedImage = await parseFromContext(
6183
6471
  arrayBuffer,
6184
6472
  [ImageLoader, BasisLoader],
6185
- {
6186
- ...options,
6187
- mimeType: image.mimeType,
6188
- basis: options.basis || { format: selectSupportedBasisFormat() }
6189
- },
6473
+ gltfOptions,
6190
6474
  context
6191
6475
  );
6192
6476
  if (parsedImage && parsedImage[0]) {
@@ -6227,18 +6511,15 @@ var __exports__ = (() => {
6227
6511
  // Create image objects
6228
6512
  decompressMeshes: true
6229
6513
  // Decompress Draco encoded meshes
6230
- },
6231
- // common?
6232
- log: console
6233
- // eslint-disable-line
6514
+ }
6234
6515
  }
6235
6516
  };
6236
6517
  async function parse2(arrayBuffer, options = {}, context) {
6237
- options = { ...GLTFLoader.options, ...options };
6238
- options.gltf = { ...GLTFLoader.options.gltf, ...options.gltf };
6239
- const { byteOffset = 0 } = options;
6518
+ const mergedOptions = { ...GLTFLoader.options, ...options };
6519
+ mergedOptions.gltf = { ...GLTFLoader.options.gltf, ...mergedOptions.gltf };
6520
+ const byteOffset = options?.glb?.byteOffset || 0;
6240
6521
  const gltf = {};
6241
- return await parseGLTF(gltf, arrayBuffer, byteOffset, options, context);
6522
+ return await parseGLTF(gltf, arrayBuffer, byteOffset, mergedOptions, context);
6242
6523
  }
6243
6524
 
6244
6525
  // src/lib/encoders/encode-glb.ts
@@ -6352,9 +6633,8 @@ var __exports__ = (() => {
6352
6633
  return parseSync(arrayBuffer, options);
6353
6634
  }
6354
6635
  function parseSync(arrayBuffer, options) {
6355
- const { byteOffset = 0 } = options || {};
6356
6636
  const glb = {};
6357
- parseGLBSync(glb, arrayBuffer, byteOffset, options?.glb);
6637
+ parseGLBSync(glb, arrayBuffer, options?.glb?.byteOffset || 0, options?.glb);
6358
6638
  return glb;
6359
6639
  }
6360
6640
 
@@ -6685,7 +6965,7 @@ var __exports__ = (() => {
6685
6965
  const buffer = accessor.bufferView.buffer;
6686
6966
  const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
6687
6967
  const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
6688
- let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
6968
+ let cutBuffer = copyToArrayBuffer(buffer.arrayBuffer, byteOffset, byteLength);
6689
6969
  if (accessor.bufferView.byteStride) {
6690
6970
  cutBuffer = this._getValueFromInterleavedBuffer(
6691
6971
  buffer,