@loaders.gl/gltf 4.4.0-alpha.18 → 4.4.0-alpha.19

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
@@ -2722,7 +2722,7 @@ var __exports__ = (() => {
2722
2722
  "bc7-rgba-unorm",
2723
2723
  "bc7-rgba-unorm-srgb"
2724
2724
  ],
2725
- WEBGL_compressed_texture_etc1: ["etc1-rbg-unorm-webgl"],
2725
+ WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
2726
2726
  WEBGL_compressed_texture_etc: [
2727
2727
  "etc2-rgb8unorm",
2728
2728
  "etc2-rgb8unorm-srgb",
@@ -2738,7 +2738,7 @@ var __exports__ = (() => {
2738
2738
  WEBGL_compressed_texture_pvrtc: [
2739
2739
  "pvrtc-rgb4unorm-webgl",
2740
2740
  "pvrtc-rgba4unorm-webgl",
2741
- "pvrtc-rbg2unorm-webgl",
2741
+ "pvrtc-rgb2unorm-webgl",
2742
2742
  "pvrtc-rgba2unorm-webgl"
2743
2743
  ],
2744
2744
  WEBGL_compressed_texture_atc: [
@@ -2838,12 +2838,13 @@ var __exports__ = (() => {
2838
2838
  }
2839
2839
 
2840
2840
  // ../textures/src/lib/parsers/parse-basis.ts
2841
+ var basisTranscodingLock = Promise.resolve();
2841
2842
  var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
2842
2843
  etc1: {
2843
2844
  basisFormat: 0,
2844
2845
  compressed: true,
2845
2846
  format: GL_COMPRESSED_RGB_ETC1_WEBGL,
2846
- textureFormat: "etc1-rbg-unorm-webgl"
2847
+ textureFormat: "etc1-rgb-unorm-webgl"
2847
2848
  },
2848
2849
  etc2: {
2849
2850
  basisFormat: 1,
@@ -2945,31 +2946,46 @@ var __exports__ = (() => {
2945
2946
  var BASIS_FORMATS = Object.freeze(
2946
2947
  Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS)
2947
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
+ }
2948
2962
  async function parseBasis(data, options = {}) {
2949
2963
  const loadLibraryOptions = extractLoadLibraryOptions(options);
2950
- if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
2951
- if (isKTX(data)) {
2952
- const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2953
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2954
- }
2955
- const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2956
- return parseBasisFile(BasisFile, data, options);
2957
- }
2958
- switch (options.basis.module) {
2959
- case "encoder":
2960
- const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
2961
- switch (options.basis.containerFormat) {
2962
- case "ktx2":
2963
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2964
- case "basis":
2965
- default:
2966
- return parseBasisFile(fileConstructors.BasisFile, data, 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);
2967
2969
  }
2968
- case "transcoder":
2969
- default:
2970
2970
  const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2971
2971
  return parseBasisFile(BasisFile, data, options);
2972
- }
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
+ });
2973
2989
  }
2974
2990
  function parseBasisFile(BasisFile, data, options) {
2975
2991
  const basisFile = new BasisFile(new Uint8Array(data));
@@ -3114,7 +3130,7 @@ var __exports__ = (() => {
3114
3130
  } else if (hasSupportedTextureFormat(textureFormats2, [
3115
3131
  "pvrtc-rgb4unorm-webgl",
3116
3132
  "pvrtc-rgba4unorm-webgl",
3117
- "pvrtc-rbg2unorm-webgl",
3133
+ "pvrtc-rgb2unorm-webgl",
3118
3134
  "pvrtc-rgba2unorm-webgl"
3119
3135
  ])) {
3120
3136
  return {
@@ -3134,7 +3150,7 @@ var __exports__ = (() => {
3134
3150
  "eac-rg11snorm"
3135
3151
  ])) {
3136
3152
  return "etc2";
3137
- } else if (textureFormats2.has("etc1-rbg-unorm-webgl")) {
3153
+ } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
3138
3154
  return "etc1";
3139
3155
  } else if (hasSupportedTextureFormat(textureFormats2, [
3140
3156
  "atc-rgb-unorm-webgl",
@@ -3291,16 +3307,26 @@ var __exports__ = (() => {
3291
3307
  }
3292
3308
 
3293
3309
  // src/lib/gltf-utils/resolve-url.ts
3294
- function resolveUrl(url, options) {
3310
+ function resolveUrl(url, options, context) {
3295
3311
  const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
3296
3312
  if (absolute) {
3297
3313
  return url;
3298
3314
  }
3299
- const baseUrl = options?.core?.baseUri || options.baseUri || options.uri;
3315
+ const baseUrl = context?.baseUrl || getResolveBaseUrl(options?.core?.baseUrl);
3300
3316
  if (!baseUrl) {
3301
- 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}`);
3318
+ }
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;
3302
3327
  }
3303
- return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url;
3328
+ const slashIndex = baseUrl.lastIndexOf("/");
3329
+ return slashIndex >= 0 ? baseUrl.slice(0, slashIndex + 1) : "";
3304
3330
  }
3305
3331
 
3306
3332
  // src/lib/extensions/EXT_meshopt_compression.ts
@@ -6345,8 +6371,8 @@ var __exports__ = (() => {
6345
6371
  return gltf;
6346
6372
  }
6347
6373
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
6348
- if (options.core?.baseUri) {
6349
- gltf.baseUri = options.core?.baseUri;
6374
+ if (options.core?.baseUrl) {
6375
+ gltf.baseUri = options.core?.baseUrl;
6350
6376
  }
6351
6377
  if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options.glb)) {
6352
6378
  const textDecoder = new TextDecoder();
@@ -6383,7 +6409,7 @@ var __exports__ = (() => {
6383
6409
  if (buffer.uri) {
6384
6410
  const { fetch: fetch2 } = context;
6385
6411
  assert3(fetch2);
6386
- const uri = resolveUrl(buffer.uri, options);
6412
+ const uri = resolveUrl(buffer.uri, options, context);
6387
6413
  const response = await context?.fetch?.(uri);
6388
6414
  const arrayBuffer = await response?.arrayBuffer?.();
6389
6415
  gltf.buffers[i] = {
@@ -6423,7 +6449,7 @@ var __exports__ = (() => {
6423
6449
  async function loadImage(gltf, image, index, options, context) {
6424
6450
  let arrayBuffer;
6425
6451
  if (image.uri && !image.hasOwnProperty("bufferView")) {
6426
- const uri = resolveUrl(image.uri, options);
6452
+ const uri = resolveUrl(image.uri, options, context);
6427
6453
  const { fetch: fetch2 } = context;
6428
6454
  const response = await fetch2(uri);
6429
6455
  arrayBuffer = await response.arrayBuffer();