@loaders.gl/gltf 4.4.0-alpha.17 → 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
@@ -170,6 +170,16 @@ var __exports__ = (() => {
170
170
 
171
171
  // ../worker-utils/src/lib/library-utils/library-utils.ts
172
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
+ }
173
183
  async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
174
184
  if (moduleName) {
175
185
  libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
@@ -2712,7 +2722,7 @@ var __exports__ = (() => {
2712
2722
  "bc7-rgba-unorm",
2713
2723
  "bc7-rgba-unorm-srgb"
2714
2724
  ],
2715
- WEBGL_compressed_texture_etc1: ["etc1-rbg-unorm-webgl"],
2725
+ WEBGL_compressed_texture_etc1: ["etc1-rgb-unorm-webgl"],
2716
2726
  WEBGL_compressed_texture_etc: [
2717
2727
  "etc2-rgb8unorm",
2718
2728
  "etc2-rgb8unorm-srgb",
@@ -2728,7 +2738,7 @@ var __exports__ = (() => {
2728
2738
  WEBGL_compressed_texture_pvrtc: [
2729
2739
  "pvrtc-rgb4unorm-webgl",
2730
2740
  "pvrtc-rgba4unorm-webgl",
2731
- "pvrtc-rbg2unorm-webgl",
2741
+ "pvrtc-rgb2unorm-webgl",
2732
2742
  "pvrtc-rgba2unorm-webgl"
2733
2743
  ],
2734
2744
  WEBGL_compressed_texture_atc: [
@@ -2828,12 +2838,13 @@ var __exports__ = (() => {
2828
2838
  }
2829
2839
 
2830
2840
  // ../textures/src/lib/parsers/parse-basis.ts
2841
+ var basisTranscodingLock = Promise.resolve();
2831
2842
  var BASIS_FORMAT_TO_OUTPUT_OPTIONS = {
2832
2843
  etc1: {
2833
2844
  basisFormat: 0,
2834
2845
  compressed: true,
2835
2846
  format: GL_COMPRESSED_RGB_ETC1_WEBGL,
2836
- textureFormat: "etc1-rbg-unorm-webgl"
2847
+ textureFormat: "etc1-rgb-unorm-webgl"
2837
2848
  },
2838
2849
  etc2: {
2839
2850
  basisFormat: 1,
@@ -2935,30 +2946,46 @@ var __exports__ = (() => {
2935
2946
  var BASIS_FORMATS = Object.freeze(
2936
2947
  Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS)
2937
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
+ }
2938
2962
  async function parseBasis(data, options = {}) {
2939
- if (!options.basis?.containerFormat || options.basis.containerFormat === "auto") {
2940
- if (isKTX(data)) {
2941
- const fileConstructors = await loadBasisEncoderModule(options?.core || {});
2942
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2943
- }
2944
- const { BasisFile } = await loadBasisTranscoderModule(options?.core || {});
2945
- return parseBasisFile(BasisFile, data, options);
2946
- }
2947
- switch (options.basis.module) {
2948
- case "encoder":
2949
- const fileConstructors = await loadBasisEncoderModule(options?.core || {});
2950
- switch (options.basis.containerFormat) {
2951
- case "ktx2":
2952
- return parseKTX2File(fileConstructors.KTX2File, data, options);
2953
- case "basis":
2954
- default:
2955
- return parseBasisFile(fileConstructors.BasisFile, 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);
2956
2969
  }
2957
- case "transcoder":
2958
- default:
2959
- const { BasisFile } = await loadBasisTranscoderModule(options.core || {});
2970
+ const { BasisFile } = await loadBasisTranscoderModule(loadLibraryOptions);
2960
2971
  return parseBasisFile(BasisFile, data, options);
2961
- }
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
+ });
2962
2989
  }
2963
2990
  function parseBasisFile(BasisFile, data, options) {
2964
2991
  const basisFile = new BasisFile(new Uint8Array(data));
@@ -3103,7 +3130,7 @@ var __exports__ = (() => {
3103
3130
  } else if (hasSupportedTextureFormat(textureFormats2, [
3104
3131
  "pvrtc-rgb4unorm-webgl",
3105
3132
  "pvrtc-rgba4unorm-webgl",
3106
- "pvrtc-rbg2unorm-webgl",
3133
+ "pvrtc-rgb2unorm-webgl",
3107
3134
  "pvrtc-rgba2unorm-webgl"
3108
3135
  ])) {
3109
3136
  return {
@@ -3123,7 +3150,7 @@ var __exports__ = (() => {
3123
3150
  "eac-rg11snorm"
3124
3151
  ])) {
3125
3152
  return "etc2";
3126
- } else if (textureFormats2.has("etc1-rbg-unorm-webgl")) {
3153
+ } else if (textureFormats2.has("etc1-rgb-unorm-webgl")) {
3127
3154
  return "etc1";
3128
3155
  } else if (hasSupportedTextureFormat(textureFormats2, [
3129
3156
  "atc-rgb-unorm-webgl",
@@ -3159,7 +3186,6 @@ var __exports__ = (() => {
3159
3186
  options: {
3160
3187
  basis: {
3161
3188
  format: "auto",
3162
- libraryPath: "libs/",
3163
3189
  containerFormat: "auto",
3164
3190
  module: "transcoder"
3165
3191
  }
@@ -3281,16 +3307,26 @@ var __exports__ = (() => {
3281
3307
  }
3282
3308
 
3283
3309
  // src/lib/gltf-utils/resolve-url.ts
3284
- function resolveUrl(url, options) {
3310
+ function resolveUrl(url, options, context) {
3285
3311
  const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
3286
3312
  if (absolute) {
3287
3313
  return url;
3288
3314
  }
3289
- const baseUrl = options?.core?.baseUri || options.baseUri || options.uri;
3315
+ const baseUrl = context?.baseUrl || getResolveBaseUrl(options?.core?.baseUrl);
3290
3316
  if (!baseUrl) {
3291
- 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;
3292
3327
  }
3293
- return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url;
3328
+ const slashIndex = baseUrl.lastIndexOf("/");
3329
+ return slashIndex >= 0 ? baseUrl.slice(0, slashIndex + 1) : "";
3294
3330
  }
3295
3331
 
3296
3332
  // src/lib/extensions/EXT_meshopt_compression.ts
@@ -4315,7 +4351,6 @@ var __exports__ = (() => {
4315
4351
  draco: {
4316
4352
  decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
4317
4353
  // 'js' for IE11
4318
- libraryPath: "libs/",
4319
4354
  extraAttributes: {},
4320
4355
  attributeNameEntry: void 0
4321
4356
  }
@@ -4327,7 +4362,7 @@ var __exports__ = (() => {
4327
4362
  };
4328
4363
  async function parse(arrayBuffer, options) {
4329
4364
  const { draco } = await loadDracoDecoderModule(
4330
- options?.core,
4365
+ extractLoadLibraryOptions(options),
4331
4366
  options?.draco?.decoderType || "wasm"
4332
4367
  );
4333
4368
  const dracoParser = new DracoParser(draco);
@@ -6336,8 +6371,8 @@ var __exports__ = (() => {
6336
6371
  return gltf;
6337
6372
  }
6338
6373
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
6339
- if (options.core?.baseUri) {
6340
- gltf.baseUri = options.core?.baseUri;
6374
+ if (options.core?.baseUrl) {
6375
+ gltf.baseUri = options.core?.baseUrl;
6341
6376
  }
6342
6377
  if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options.glb)) {
6343
6378
  const textDecoder = new TextDecoder();
@@ -6374,7 +6409,7 @@ var __exports__ = (() => {
6374
6409
  if (buffer.uri) {
6375
6410
  const { fetch: fetch2 } = context;
6376
6411
  assert3(fetch2);
6377
- const uri = resolveUrl(buffer.uri, options);
6412
+ const uri = resolveUrl(buffer.uri, options, context);
6378
6413
  const response = await context?.fetch?.(uri);
6379
6414
  const arrayBuffer = await response?.arrayBuffer?.();
6380
6415
  gltf.buffers[i] = {
@@ -6414,7 +6449,7 @@ var __exports__ = (() => {
6414
6449
  async function loadImage(gltf, image, index, options, context) {
6415
6450
  let arrayBuffer;
6416
6451
  if (image.uri && !image.hasOwnProperty("bufferView")) {
6417
- const uri = resolveUrl(image.uri, options);
6452
+ const uri = resolveUrl(image.uri, options, context);
6418
6453
  const { fetch: fetch2 } = context;
6419
6454
  const response = await fetch2(uri);
6420
6455
  arrayBuffer = await response.arrayBuffer();