@loaders.gl/gltf 4.4.0-alpha.9 → 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.
package/dist/index.cjs CHANGED
@@ -1695,7 +1695,7 @@ function processPrimitiveTextures(scenegraph, attributeName, featureTexturePrope
1695
1695
  }
1696
1696
 
1697
1697
  // dist/lib/utils/version.js
1698
- var VERSION = true ? "4.4.0-alpha.9" : "latest";
1698
+ var VERSION = true ? "4.4.0" : "latest";
1699
1699
 
1700
1700
  // dist/lib/parsers/parse-gltf.js
1701
1701
  var import_loader_utils7 = require("@loaders.gl/loader-utils");
@@ -1814,17 +1814,27 @@ function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
1814
1814
  }
1815
1815
 
1816
1816
  // dist/lib/gltf-utils/resolve-url.js
1817
- function resolveUrl(url, options) {
1817
+ function resolveUrl(url, options, context) {
1818
1818
  var _a;
1819
1819
  const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
1820
1820
  if (absolute) {
1821
1821
  return url;
1822
1822
  }
1823
- const baseUrl = ((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.baseUri) || options.baseUri || options.uri;
1823
+ const baseUrl = (context == null ? void 0 : context.baseUrl) || getResolveBaseUrl((_a = options == null ? void 0 : options.core) == null ? void 0 : _a.baseUrl);
1824
1824
  if (!baseUrl) {
1825
- throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
1825
+ throw new Error(`'baseUrl' must be provided to resolve relative url ${url}`);
1826
1826
  }
1827
- return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url;
1827
+ return baseUrl.endsWith("/") ? `${baseUrl}${url}` : `${baseUrl}/${url}`;
1828
+ }
1829
+ function getResolveBaseUrl(baseUrl) {
1830
+ if (!baseUrl) {
1831
+ return void 0;
1832
+ }
1833
+ if (baseUrl.endsWith("/")) {
1834
+ return baseUrl;
1835
+ }
1836
+ const slashIndex = baseUrl.lastIndexOf("/");
1837
+ return slashIndex >= 0 ? baseUrl.slice(0, slashIndex + 1) : "";
1828
1838
  }
1829
1839
 
1830
1840
  // dist/lib/extensions/EXT_meshopt_compression.js
@@ -2887,8 +2897,8 @@ async function parseGLTF(gltf, arrayBufferOrString, byteOffset = 0, options, con
2887
2897
  }
2888
2898
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
2889
2899
  var _a, _b;
2890
- if ((_a = options.core) == null ? void 0 : _a.baseUri) {
2891
- gltf.baseUri = (_b = options.core) == null ? void 0 : _b.baseUri;
2900
+ if ((_a = options.core) == null ? void 0 : _a.baseUrl) {
2901
+ gltf.baseUri = (_b = options.core) == null ? void 0 : _b.baseUrl;
2892
2902
  }
2893
2903
  if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options.glb)) {
2894
2904
  const textDecoder = new TextDecoder();
@@ -2926,7 +2936,7 @@ async function loadBuffers(gltf, options, context) {
2926
2936
  if (buffer.uri) {
2927
2937
  const { fetch } = context;
2928
2938
  assert(fetch);
2929
- const uri = resolveUrl(buffer.uri, options);
2939
+ const uri = resolveUrl(buffer.uri, options, context);
2930
2940
  const response = await ((_a = context == null ? void 0 : context.fetch) == null ? void 0 : _a.call(context, uri));
2931
2941
  const arrayBuffer = await ((_b = response == null ? void 0 : response.arrayBuffer) == null ? void 0 : _b.call(response));
2932
2942
  gltf.buffers[i] = {
@@ -2966,7 +2976,7 @@ function getReferencesImageIndices(gltf) {
2966
2976
  async function loadImage(gltf, image, index, options, context) {
2967
2977
  let arrayBuffer;
2968
2978
  if (image.uri && !image.hasOwnProperty("bufferView")) {
2969
- const uri = resolveUrl(image.uri, options);
2979
+ const uri = resolveUrl(image.uri, options, context);
2970
2980
  const { fetch } = context;
2971
2981
  const response = await fetch(uri);
2972
2982
  arrayBuffer = await response.arrayBuffer();
@@ -2982,8 +2992,7 @@ async function loadImage(gltf, image, index, options, context) {
2982
2992
  const strictOptions = options;
2983
2993
  const gltfOptions = {
2984
2994
  ...strictOptions,
2985
- core: { ...strictOptions == null ? void 0 : strictOptions.core, mimeType: image.mimeType },
2986
- basis: strictOptions.basis || { format: (0, import_textures.selectSupportedBasisFormat)() }
2995
+ core: { ...strictOptions == null ? void 0 : strictOptions.core, mimeType: image.mimeType }
2987
2996
  };
2988
2997
  let parsedImage = await (0, import_loader_utils7.parseFromContext)(arrayBuffer, [import_images4.ImageLoader, import_textures.BasisLoader], gltfOptions, context);
2989
2998
  if (parsedImage && parsedImage[0]) {