@galacean/engine-loader 2.0.0-alpha.41 → 2.0.0-alpha.43

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/module.js CHANGED
@@ -115,10 +115,11 @@ function _create_class(Constructor, protoProps, staticProps) {
115
115
  }
116
116
 
117
117
  var BufferReader = /*#__PURE__*/ function() {
118
- function BufferReader(data, byteOffset, byteLength, littleEndian) {
118
+ function BufferReader(data, byteOffset, byteLength, littleEndian, header) {
119
119
  if (byteOffset === void 0) byteOffset = 0;
120
120
  if (littleEndian === void 0) littleEndian = true;
121
121
  this.data = data;
122
+ this.header = header;
122
123
  this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength != null ? byteLength : data.byteLength - byteOffset);
123
124
  this._littleEndian = littleEndian;
124
125
  this._position = 0;
@@ -318,8 +319,11 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
318
319
  function AnimationClipDecoder() {}
319
320
  AnimationClipDecoder.decode = function decode(engine, bufferReader) {
320
321
  return new AssetPromise(function(resolve) {
322
+ var _bufferReader_header;
321
323
  var name = bufferReader.nextStr();
322
324
  var clip = new AnimationClip(name);
325
+ var _bufferReader_header_version;
326
+ var version = (_bufferReader_header_version = (_bufferReader_header = bufferReader.header) == null ? void 0 : _bufferReader_header.version) != null ? _bufferReader_header_version : 1;
323
327
  var eventsLen = bufferReader.nextUint16();
324
328
  for(var i = 0; i < eventsLen; ++i){
325
329
  var event = new AnimationEvent();
@@ -333,6 +337,7 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
333
337
  var relativePath = bufferReader.nextStr();
334
338
  var componentStr = bufferReader.nextStr();
335
339
  var componentType = Loader.getClass(componentStr);
340
+ var typeIndex = version >= 2 ? bufferReader.nextUint16() : 0;
336
341
  var property = bufferReader.nextStr();
337
342
  var getProperty = bufferReader.nextStr();
338
343
  var curve = void 0;
@@ -494,7 +499,7 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
494
499
  break;
495
500
  }
496
501
  }
497
- clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
502
+ clip.addCurveBinding(relativePath, componentType, typeIndex, property, getProperty, curve);
498
503
  }
499
504
  resolve(clip);
500
505
  });
@@ -1323,8 +1328,8 @@ function _instanceof(left, right) {
1323
1328
  }
1324
1329
  var _proto = PrefabResource.prototype;
1325
1330
  /**
1326
- * Instantiate prefab.
1327
- * @returns prefab's root entity
1331
+ * Instantiate the prefab.
1332
+ * @returns A detached prefab instance that must be added to a parent Entity or Scene to update and render
1328
1333
  */ _proto.instantiate = function instantiate() {
1329
1334
  var _this__root;
1330
1335
  return (_this__root = this._root) == null ? void 0 : _this__root.clone();
@@ -1676,7 +1681,7 @@ var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
1676
1681
  }
1677
1682
  var _decoderMap_header_type;
1678
1683
  var header = FileHeader.decode(arrayBuffer);
1679
- var bufferReader = new BufferReader(new Uint8Array(arrayBuffer), header.headerLength, header.dataLength);
1684
+ var bufferReader = new BufferReader(new Uint8Array(arrayBuffer), header.headerLength, header.dataLength, true, header);
1680
1685
  return (_decoderMap_header_type = decoderMap[header.type]).decode.apply(_decoderMap_header_type, [].concat([
1681
1686
  engine,
1682
1687
  bufferReader
@@ -2479,18 +2484,19 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
2479
2484
  /**
2480
2485
  * @internal
2481
2486
  */ _proto.load = function load(item, resourceManager) {
2487
+ // @ts-expect-error -- internal method is omitted from public declarations
2488
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
2482
2489
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
2483
2490
  var requestConfig = _extends({}, item, {
2484
2491
  type: "arraybuffer"
2485
2492
  });
2486
- var url = item.url;
2487
2493
  resourceManager// @ts-ignore
2488
- ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
2494
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
2489
2495
  return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2490
2496
  var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2491
2497
  return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
2492
2498
  }).then(function(texture) {
2493
- resourceManager.addContentRestorer(new KTX2ContentRestorer(texture, url, requestConfig));
2499
+ resourceManager.addContentRestorer(new KTX2ContentRestorer(texture, remoteUrl, requestConfig));
2494
2500
  resolve(texture);
2495
2501
  });
2496
2502
  }).catch(reject);
@@ -2674,9 +2680,9 @@ KTX2Loader = __decorate([
2674
2680
  ], KTX2Loader);
2675
2681
  var KTX2ContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2676
2682
  _inherits(KTX2ContentRestorer, ContentRestorer);
2677
- function KTX2ContentRestorer(resource, url, requestConfig) {
2683
+ function KTX2ContentRestorer(resource, remoteUrl, requestConfig) {
2678
2684
  var _this;
2679
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
2685
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
2680
2686
  return _this;
2681
2687
  }
2682
2688
  var _proto = KTX2ContentRestorer.prototype;
@@ -2686,7 +2692,7 @@ var KTX2ContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2686
2692
  var engine = resource.engine;
2687
2693
  return new AssetPromise(function(resolve, reject) {
2688
2694
  engine.resourceManager// @ts-ignore
2689
- ._request(_this.url, requestConfig).then(function(buffer) {
2695
+ ._requestByRemoteUrl(_this.remoteUrl, requestConfig).then(function(buffer) {
2690
2696
  return KTX2Loader._parseBuffer(new Uint8Array(buffer), engine, requestConfig.params).then(function(param) {
2691
2697
  var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2692
2698
  return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params, resource);
@@ -2704,21 +2710,22 @@ var AmbientLightLoader = /*#__PURE__*/ function(Loader) {
2704
2710
  }
2705
2711
  var _proto = AmbientLightLoader.prototype;
2706
2712
  _proto.load = function load(item, resourceManager) {
2713
+ // @ts-expect-error -- internal method is omitted from public declarations
2714
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
2707
2715
  return new AssetPromise(function(resolve, reject) {
2708
2716
  var requestConfig = _extends({}, item, {
2709
2717
  type: "arraybuffer"
2710
2718
  });
2711
2719
  var engine = resourceManager.engine;
2712
- var url = item.url;
2713
2720
  resourceManager// @ts-ignore
2714
- ._request(url, requestConfig).then(function(buffer) {
2721
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(buffer) {
2715
2722
  var header = FileHeader.decode(buffer);
2716
2723
  var dataOffset = header.headerLength;
2717
2724
  var sh = new SphericalHarmonics3();
2718
2725
  sh.copyFromArray(new Float32Array(buffer, dataOffset, 27));
2719
2726
  var textureOffset = dataOffset + AmbientLightLoader._shByteLength;
2720
2727
  return AmbientLightLoader._parseTexture(engine, buffer, textureOffset, header.dataLength - AmbientLightLoader._shByteLength).then(function(specularTexture) {
2721
- engine.resourceManager.addContentRestorer(new AmbientLightContentRestorer(specularTexture, url, requestConfig));
2728
+ engine.resourceManager.addContentRestorer(new AmbientLightContentRestorer(specularTexture, remoteUrl, requestConfig));
2722
2729
  var ambientLight = new AmbientLight(engine);
2723
2730
  ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
2724
2731
  ambientLight.diffuseSphericalHarmonics = sh;
@@ -2767,9 +2774,9 @@ AmbientLightLoader = __decorate([
2767
2774
  * @internal
2768
2775
  */ var AmbientLightContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2769
2776
  _inherits(AmbientLightContentRestorer, ContentRestorer);
2770
- function AmbientLightContentRestorer(resource, url, requestConfig) {
2777
+ function AmbientLightContentRestorer(resource, remoteUrl, requestConfig) {
2771
2778
  var _this;
2772
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
2779
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
2773
2780
  return _this;
2774
2781
  }
2775
2782
  var _proto = AmbientLightContentRestorer.prototype;
@@ -2779,7 +2786,7 @@ AmbientLightLoader = __decorate([
2779
2786
  var resource = _this.resource;
2780
2787
  var engine = resource.engine;
2781
2788
  engine.resourceManager// @ts-ignore
2782
- ._request(_this.url, _this.requestConfig).then(function(buffer) {
2789
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(buffer) {
2783
2790
  var header = FileHeader.decode(buffer);
2784
2791
  var dataOffset = header.headerLength;
2785
2792
  var textureOffset = dataOffset + AmbientLightLoader._shByteLength;
@@ -2836,7 +2843,10 @@ var FontLoader = /*#__PURE__*/ function(Loader) {
2836
2843
  })).then(function(data) {
2837
2844
  var fontName = data.fontName, fontUrl = data.fontUrl;
2838
2845
  if (fontUrl) {
2839
- _this._registerFont(fontName, fontUrl).then(function() {
2846
+ var absoluteUrl = Utils.resolveAbsoluteUrl(item.url, fontUrl);
2847
+ // @ts-ignore
2848
+ var remoteUrl = resourceManager._getRemoteUrl(absoluteUrl);
2849
+ _this._registerFont(fontName, remoteUrl).then(function() {
2840
2850
  var font = new Font(resourceManager.engine, fontName);
2841
2851
  resolve(font);
2842
2852
  }).catch(function(e) {
@@ -3089,9 +3099,9 @@ function getMeshoptDecoder() {
3089
3099
  }
3090
3100
  var _proto = GLTFResource.prototype;
3091
3101
  /**
3092
- * Instantiate scene root entity.
3093
- * @param sceneIndex - Scene index
3094
- * @returns Root entity
3102
+ * Instantiate a glTF scene root Entity.
3103
+ * @param sceneIndex - The scene index
3104
+ * @returns A detached scene-root instance that must be added to a parent Entity or Scene to update and render
3095
3105
  */ _proto.instantiateSceneRoot = function instantiateSceneRoot(sceneIndex) {
3096
3106
  var sceneRoot = sceneIndex === undefined ? this._defaultSceneRoot : this._sceneRoots[sceneIndex];
3097
3107
  return sceneRoot.clone();
@@ -3330,6 +3340,8 @@ function getMeshoptDecoder() {
3330
3340
  detail.total = total;
3331
3341
  _this._setTaskDetailProgress(url, loaded, total);
3332
3342
  };
3343
+ // @ts-expect-error -- internal method is omitted from public declarations
3344
+ this._remoteAssetBaseURL = resourceManager._getRemoteUrl(glTFResource.url);
3333
3345
  this.contentRestorer = new GLTFContentRestorer(glTFResource);
3334
3346
  }
3335
3347
  var _proto = GLTFParserContext.prototype;
@@ -3420,7 +3432,7 @@ function getMeshoptDecoder() {
3420
3432
  var _this_glTFResource, _glTFResourceKey;
3421
3433
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
3422
3434
  } else {
3423
- var url = this.glTFResource.url;
3435
+ var remoteAssetBaseURL = this._remoteAssetBaseURL;
3424
3436
  resource.then(function(item) {
3425
3437
  if (index == undefined) {
3426
3438
  _this.glTFResource[glTFResourceKey] = item;
@@ -3432,15 +3444,15 @@ function getMeshoptDecoder() {
3432
3444
  for(var i = 0, length = item.length; i < length; i++){
3433
3445
  var mesh = item[i];
3434
3446
  // @ts-ignore
3435
- _this.resourceManager._onSubAssetSuccess(url, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
3447
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
3436
3448
  }
3437
3449
  } else {
3438
3450
  // @ts-ignore
3439
- _this.resourceManager._onSubAssetSuccess(url, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
3451
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
3440
3452
  var _this_glTF_scene;
3441
3453
  if (type === 2 && ((_this_glTF_scene = _this.glTF.scene) != null ? _this_glTF_scene : 0) === index) {
3442
3454
  // @ts-ignore
3443
- _this.resourceManager._onSubAssetSuccess(url, "defaultSceneRoot", item);
3455
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "defaultSceneRoot", item);
3444
3456
  }
3445
3457
  }
3446
3458
  }).catch(function(e) {
@@ -4478,16 +4490,16 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
4478
4490
  _proto._parseSingleBuffer = function _parseSingleBuffer(context, bufferInfo) {
4479
4491
  var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer, resourceManager = context.resourceManager;
4480
4492
  var url = glTFResource.url;
4493
+ var absoluteUrl = Utils.resolveAbsoluteUrl(url, bufferInfo.uri);
4481
4494
  // @ts-ignore
4482
- var remoteUrl = resourceManager._getRemoteUrl(url);
4495
+ var remoteUrl = resourceManager._getRemoteUrl(absoluteUrl);
4483
4496
  var restoreBufferRequests = contentRestorer.bufferRequests;
4484
4497
  var requestConfig = {
4485
4498
  type: "arraybuffer"
4486
4499
  };
4487
- var absoluteUrl = Utils.resolveAbsoluteUrl(remoteUrl, bufferInfo.uri);
4488
- restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
4500
+ restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig));
4489
4501
  var promise = resourceManager// @ts-ignore
4490
- ._requestByRemoteUrl(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
4502
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
4491
4503
  context._addTaskCompletePromise(promise);
4492
4504
  return promise;
4493
4505
  };
@@ -5705,12 +5717,14 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
5705
5717
  }
5706
5718
  var _proto = KTXLoader.prototype;
5707
5719
  _proto.load = function load(item, resourceManager) {
5720
+ // @ts-expect-error -- internal method is omitted from public declarations
5721
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
5708
5722
  var requestConfig = _extends({}, item, {
5709
5723
  type: "arraybuffer"
5710
5724
  });
5711
5725
  return new AssetPromise(function(resolve, reject) {
5712
5726
  resourceManager// @ts-ignore
5713
- ._request(item.url, requestConfig).then(function(bin) {
5727
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(bin) {
5714
5728
  var parsedData = parseSingleKTX(bin);
5715
5729
  var width = parsedData.width, height = parsedData.height, mipmaps = parsedData.mipmaps, engineFormat = parsedData.engineFormat;
5716
5730
  var mipmap = mipmaps.length > 1;
@@ -5719,7 +5733,7 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
5719
5733
  var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
5720
5734
  texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
5721
5735
  }
5722
- resourceManager.addContentRestorer(new KTXContentRestorer(texture, item.url, requestConfig));
5736
+ resourceManager.addContentRestorer(new KTXContentRestorer(texture, remoteUrl, requestConfig));
5723
5737
  resolve(texture);
5724
5738
  }).catch(function(e) {
5725
5739
  reject(e);
@@ -5735,9 +5749,9 @@ KTXLoader = __decorate([
5735
5749
  ], KTXLoader);
5736
5750
  var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5737
5751
  _inherits(KTXContentRestorer, ContentRestorer);
5738
- function KTXContentRestorer(resource, url, requestConfig) {
5752
+ function KTXContentRestorer(resource, remoteUrl, requestConfig) {
5739
5753
  var _this;
5740
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
5754
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
5741
5755
  return _this;
5742
5756
  }
5743
5757
  var _proto = KTXContentRestorer.prototype;
@@ -5747,7 +5761,7 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5747
5761
  var engine = resource.engine;
5748
5762
  return new AssetPromise(function(resolve, reject) {
5749
5763
  engine.resourceManager// @ts-ignore
5750
- ._request(_this.url, _this.requestConfig).then(function(bin) {
5764
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(bin) {
5751
5765
  var mipmaps = parseSingleKTX(bin).mipmaps;
5752
5766
  for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
5753
5767
  var _mipmaps_miplevel = mipmaps[miplevel], width = _mipmaps_miplevel.width, height = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
@@ -5858,13 +5872,14 @@ var MeshLoader = /*#__PURE__*/ function(Loader) {
5858
5872
  var requestConfig = _extends({}, item, {
5859
5873
  type: "arraybuffer"
5860
5874
  });
5861
- var url = item.url;
5875
+ // @ts-expect-error -- internal method is omitted from public declarations
5876
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
5862
5877
  return new AssetPromise(function(resolve, reject) {
5863
5878
  resourceManager// @ts-ignore
5864
- ._request(url, requestConfig).then(function(data) {
5879
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(data) {
5865
5880
  return decode(data, resourceManager.engine);
5866
5881
  }).then(function(mesh) {
5867
- resourceManager.addContentRestorer(new MeshContentRestorer(mesh, url, requestConfig));
5882
+ resourceManager.addContentRestorer(new MeshContentRestorer(mesh, remoteUrl, requestConfig));
5868
5883
  resolve(mesh);
5869
5884
  }).catch(reject);
5870
5885
  });
@@ -5878,9 +5893,9 @@ MeshLoader = __decorate([
5878
5893
  ], MeshLoader);
5879
5894
  var MeshContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5880
5895
  _inherits(MeshContentRestorer, ContentRestorer);
5881
- function MeshContentRestorer(resource, url, requestConfig) {
5896
+ function MeshContentRestorer(resource, remoteUrl, requestConfig) {
5882
5897
  var _this;
5883
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
5898
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
5884
5899
  return _this;
5885
5900
  }
5886
5901
  var _proto = MeshContentRestorer.prototype;
@@ -5890,7 +5905,7 @@ var MeshContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5890
5905
  var engine = resource.engine;
5891
5906
  return new AssetPromise(function(resolve, reject) {
5892
5907
  engine.resourceManager// @ts-ignore
5893
- ._request(_this.url, _this.requestConfig).then(function(data) {
5908
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(data) {
5894
5909
  return decode(data, engine, resource);
5895
5910
  }).then(function(mesh) {
5896
5911
  resolve(mesh);
@@ -6196,14 +6211,16 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6196
6211
  _proto.load = function load(item, resourceManager) {
6197
6212
  var _this = this;
6198
6213
  var url = item.url;
6214
+ // @ts-expect-error -- internal method is omitted from public declarations
6215
+ var remoteUrl = resourceManager._getRemoteUrl(url);
6199
6216
  var requestConfig = _extends({}, item, {
6200
6217
  type: "arraybuffer"
6201
6218
  });
6202
6219
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
6203
6220
  resourceManager// @ts-ignore
6204
- ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
6221
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
6205
6222
  _this._decode(buffer, item, resourceManager).then(function(texture) {
6206
- resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
6223
+ resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, remoteUrl, requestConfig));
6207
6224
  resolve(texture);
6208
6225
  }, reject);
6209
6226
  }).catch(reject);
@@ -6240,29 +6257,17 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6240
6257
  };
6241
6258
  _proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
6242
6259
  var _this = this;
6243
- return new AssetPromise(function(resolve, reject) {
6244
- var blob = new Blob([
6245
- buffer
6246
- ]);
6247
- var img = new Image();
6248
- img.onload = function() {
6249
- URL.revokeObjectURL(img.src);
6250
- var _item_params;
6251
- var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
6252
- var engine = resourceManager.engine;
6253
- var width = img.width, height = img.height;
6254
- var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
6255
- var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
6256
- texture.setImageSource(img);
6257
- generateMipmap && texture.generateMipmaps();
6258
- _this._applyParams(texture, item);
6259
- resolve(texture);
6260
- };
6261
- img.onerror = function(e) {
6262
- URL.revokeObjectURL(img.src);
6263
- reject(e);
6264
- };
6265
- img.src = URL.createObjectURL(blob);
6260
+ return decodeImage(buffer, item.url).then(function(img) {
6261
+ var _item_params;
6262
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
6263
+ var engine = resourceManager.engine;
6264
+ var width = img.width, height = img.height;
6265
+ var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
6266
+ var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
6267
+ texture.setImageSource(img);
6268
+ generateMipmap && texture.generateMipmaps();
6269
+ _this._applyParams(texture, item);
6270
+ return texture;
6266
6271
  });
6267
6272
  };
6268
6273
  _proto._applyParams = function _applyParams(texture, item) {
@@ -6291,16 +6296,16 @@ TextureLoader = __decorate([
6291
6296
  ], TextureLoader);
6292
6297
  var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6293
6298
  _inherits(TextureContentRestorer, ContentRestorer);
6294
- function TextureContentRestorer(resource, url, requestConfig) {
6299
+ function TextureContentRestorer(resource, url, remoteUrl, requestConfig) {
6295
6300
  var _this;
6296
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
6301
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
6297
6302
  return _this;
6298
6303
  }
6299
6304
  var _proto = TextureContentRestorer.prototype;
6300
6305
  _proto.restoreContent = function restoreContent() {
6301
6306
  var _this = this;
6302
6307
  return this.resource.engine.resourceManager// @ts-ignore
6303
- ._request(this.url, this.requestConfig).then(function(buffer) {
6308
+ ._requestByRemoteUrl(this.remoteUrl, this.requestConfig).then(function(buffer) {
6304
6309
  if (FileHeader.checkMagic(buffer)) {
6305
6310
  return decode(buffer, _this.resource.engine, _this.resource);
6306
6311
  }
@@ -6312,27 +6317,35 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6312
6317
  texture.mipmapCount > 1 && texture.generateMipmaps();
6313
6318
  return texture;
6314
6319
  }
6315
- return new AssetPromise(function(resolve, reject) {
6316
- var blob = new Blob([
6317
- buffer
6318
- ]);
6319
- var img = new Image();
6320
- img.onload = function() {
6321
- URL.revokeObjectURL(img.src);
6322
- texture.setImageSource(img);
6323
- texture.mipmapCount > 1 && texture.generateMipmaps();
6324
- resolve(texture);
6325
- };
6326
- img.onerror = function(e) {
6327
- URL.revokeObjectURL(img.src);
6328
- reject(e);
6329
- };
6330
- img.src = URL.createObjectURL(blob);
6320
+ return decodeImage(buffer, _this.url).then(function(img) {
6321
+ texture.setImageSource(img);
6322
+ texture.mipmapCount > 1 && texture.generateMipmaps();
6323
+ return texture;
6331
6324
  });
6332
6325
  });
6333
6326
  };
6334
6327
  return TextureContentRestorer;
6335
6328
  }(ContentRestorer);
6329
+ function decodeImage(buffer, url) {
6330
+ return new AssetPromise(function(resolve, reject) {
6331
+ var objectUrl = URL.createObjectURL(new Blob([
6332
+ buffer
6333
+ ]));
6334
+ var image = new Image();
6335
+ var releaseObjectUrl = function() {
6336
+ return URL.revokeObjectURL(objectUrl);
6337
+ };
6338
+ image.onload = function() {
6339
+ releaseObjectUrl();
6340
+ resolve(image);
6341
+ };
6342
+ image.onerror = function() {
6343
+ releaseObjectUrl();
6344
+ reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + buffer.byteLength + " bytes)."));
6345
+ };
6346
+ image.src = objectUrl;
6347
+ });
6348
+ }
6336
6349
 
6337
6350
  var AudioLoader = /*#__PURE__*/ function(Loader) {
6338
6351
  _inherits(AudioLoader, Loader);
@@ -6449,8 +6462,10 @@ var RenderTargetLoader = /*#__PURE__*/ function(Loader) {
6449
6462
  var _proto = RenderTargetLoader.prototype;
6450
6463
  _proto.load = function load(item, resourceManager) {
6451
6464
  var engine = resourceManager.engine;
6465
+ // @ts-expect-error -- internal method is omitted from public declarations
6466
+ var remoteAssetBaseURL = resourceManager._getRemoteUrl(item.url);
6452
6467
  return resourceManager// @ts-ignore
6453
- ._request(item.url, _extends({}, item, {
6468
+ ._requestByRemoteUrl(remoteAssetBaseURL, _extends({}, item, {
6454
6469
  type: "json"
6455
6470
  })).then(function(data) {
6456
6471
  var width = data.width, height = data.height, colorFormats = data.colorFormats, depthFormat = data.depthFormat, antiAliasing = data.antiAliasing, autoGenerateMipmaps = data.autoGenerateMipmaps;
@@ -6476,7 +6491,7 @@ var RenderTargetLoader = /*#__PURE__*/ function(Loader) {
6476
6491
  // Notify pending sub-asset requests for colorTextures
6477
6492
  for(var i = 0, n = colorTextures.length; i < n; i++){
6478
6493
  // @ts-ignore
6479
- resourceManager._onSubAssetSuccess(item.url, "colorTextures[" + i + "]", colorTextures[i]);
6494
+ resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "colorTextures[" + i + "]", colorTextures[i]);
6480
6495
  }
6481
6496
  return rt;
6482
6497
  });