@galacean/engine-loader 2.0.0-alpha.40 → 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/main.js CHANGED
@@ -119,10 +119,11 @@ function _create_class(Constructor, protoProps, staticProps) {
119
119
  }
120
120
 
121
121
  var BufferReader = /*#__PURE__*/ function() {
122
- function BufferReader(data, byteOffset, byteLength, littleEndian) {
122
+ function BufferReader(data, byteOffset, byteLength, littleEndian, header) {
123
123
  if (byteOffset === void 0) byteOffset = 0;
124
124
  if (littleEndian === void 0) littleEndian = true;
125
125
  this.data = data;
126
+ this.header = header;
126
127
  this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength != null ? byteLength : data.byteLength - byteOffset);
127
128
  this._littleEndian = littleEndian;
128
129
  this._position = 0;
@@ -322,8 +323,11 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
322
323
  function AnimationClipDecoder() {}
323
324
  AnimationClipDecoder.decode = function decode(engine, bufferReader) {
324
325
  return new engineCore.AssetPromise(function(resolve) {
326
+ var _bufferReader_header;
325
327
  var name = bufferReader.nextStr();
326
328
  var clip = new engineCore.AnimationClip(name);
329
+ var _bufferReader_header_version;
330
+ var version = (_bufferReader_header_version = (_bufferReader_header = bufferReader.header) == null ? void 0 : _bufferReader_header.version) != null ? _bufferReader_header_version : 1;
327
331
  var eventsLen = bufferReader.nextUint16();
328
332
  for(var i = 0; i < eventsLen; ++i){
329
333
  var event = new engineCore.AnimationEvent();
@@ -337,6 +341,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
337
341
  var relativePath = bufferReader.nextStr();
338
342
  var componentStr = bufferReader.nextStr();
339
343
  var componentType = engineCore.Loader.getClass(componentStr);
344
+ var typeIndex = version >= 2 ? bufferReader.nextUint16() : 0;
340
345
  var property = bufferReader.nextStr();
341
346
  var getProperty = bufferReader.nextStr();
342
347
  var curve = void 0;
@@ -498,7 +503,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
498
503
  break;
499
504
  }
500
505
  }
501
- clip.addCurveBinding(relativePath, componentType, property, getProperty, curve);
506
+ clip.addCurveBinding(relativePath, componentType, typeIndex, property, getProperty, curve);
502
507
  }
503
508
  resolve(clip);
504
509
  });
@@ -1327,8 +1332,8 @@ function _instanceof(left, right) {
1327
1332
  }
1328
1333
  var _proto = PrefabResource.prototype;
1329
1334
  /**
1330
- * Instantiate prefab.
1331
- * @returns prefab's root entity
1335
+ * Instantiate the prefab.
1336
+ * @returns A detached prefab instance that must be added to a parent Entity or Scene to update and render
1332
1337
  */ _proto.instantiate = function instantiate() {
1333
1338
  var _this__root;
1334
1339
  return (_this__root = this._root) == null ? void 0 : _this__root.clone();
@@ -1680,7 +1685,7 @@ var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
1680
1685
  }
1681
1686
  var _decoderMap_header_type;
1682
1687
  var header = FileHeader.decode(arrayBuffer);
1683
- var bufferReader = new BufferReader(new Uint8Array(arrayBuffer), header.headerLength, header.dataLength);
1688
+ var bufferReader = new BufferReader(new Uint8Array(arrayBuffer), header.headerLength, header.dataLength, true, header);
1684
1689
  return (_decoderMap_header_type = decoderMap[header.type]).decode.apply(_decoderMap_header_type, [].concat([
1685
1690
  engine,
1686
1691
  bufferReader
@@ -2483,18 +2488,19 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
2483
2488
  /**
2484
2489
  * @internal
2485
2490
  */ _proto.load = function load(item, resourceManager) {
2491
+ // @ts-expect-error -- internal method is omitted from public declarations
2492
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
2486
2493
  return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
2487
2494
  var requestConfig = _extends({}, item, {
2488
2495
  type: "arraybuffer"
2489
2496
  });
2490
- var url = item.url;
2491
2497
  resourceManager// @ts-ignore
2492
- ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
2498
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
2493
2499
  return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
2494
2500
  var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2495
2501
  return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
2496
2502
  }).then(function(texture) {
2497
- resourceManager.addContentRestorer(new KTX2ContentRestorer(texture, url, requestConfig));
2503
+ resourceManager.addContentRestorer(new KTX2ContentRestorer(texture, remoteUrl, requestConfig));
2498
2504
  resolve(texture);
2499
2505
  });
2500
2506
  }).catch(reject);
@@ -2678,9 +2684,9 @@ exports.KTX2Loader = __decorate([
2678
2684
  ], exports.KTX2Loader);
2679
2685
  var KTX2ContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2680
2686
  _inherits(KTX2ContentRestorer, ContentRestorer);
2681
- function KTX2ContentRestorer(resource, url, requestConfig) {
2687
+ function KTX2ContentRestorer(resource, remoteUrl, requestConfig) {
2682
2688
  var _this;
2683
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
2689
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
2684
2690
  return _this;
2685
2691
  }
2686
2692
  var _proto = KTX2ContentRestorer.prototype;
@@ -2690,7 +2696,7 @@ var KTX2ContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2690
2696
  var engine = resource.engine;
2691
2697
  return new engineCore.AssetPromise(function(resolve, reject) {
2692
2698
  engine.resourceManager// @ts-ignore
2693
- ._request(_this.url, requestConfig).then(function(buffer) {
2699
+ ._requestByRemoteUrl(_this.remoteUrl, requestConfig).then(function(buffer) {
2694
2700
  return exports.KTX2Loader._parseBuffer(new Uint8Array(buffer), engine, requestConfig.params).then(function(param) {
2695
2701
  var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
2696
2702
  return exports.KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params, resource);
@@ -2708,21 +2714,22 @@ var AmbientLightLoader = /*#__PURE__*/ function(Loader) {
2708
2714
  }
2709
2715
  var _proto = AmbientLightLoader.prototype;
2710
2716
  _proto.load = function load(item, resourceManager) {
2717
+ // @ts-expect-error -- internal method is omitted from public declarations
2718
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
2711
2719
  return new engineCore.AssetPromise(function(resolve, reject) {
2712
2720
  var requestConfig = _extends({}, item, {
2713
2721
  type: "arraybuffer"
2714
2722
  });
2715
2723
  var engine = resourceManager.engine;
2716
- var url = item.url;
2717
2724
  resourceManager// @ts-ignore
2718
- ._request(url, requestConfig).then(function(buffer) {
2725
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(buffer) {
2719
2726
  var header = FileHeader.decode(buffer);
2720
2727
  var dataOffset = header.headerLength;
2721
2728
  var sh = new engineMath.SphericalHarmonics3();
2722
2729
  sh.copyFromArray(new Float32Array(buffer, dataOffset, 27));
2723
2730
  var textureOffset = dataOffset + AmbientLightLoader._shByteLength;
2724
2731
  return AmbientLightLoader._parseTexture(engine, buffer, textureOffset, header.dataLength - AmbientLightLoader._shByteLength).then(function(specularTexture) {
2725
- engine.resourceManager.addContentRestorer(new AmbientLightContentRestorer(specularTexture, url, requestConfig));
2732
+ engine.resourceManager.addContentRestorer(new AmbientLightContentRestorer(specularTexture, remoteUrl, requestConfig));
2726
2733
  var ambientLight = new engineCore.AmbientLight(engine);
2727
2734
  ambientLight.diffuseMode = engineCore.DiffuseMode.SphericalHarmonics;
2728
2735
  ambientLight.diffuseSphericalHarmonics = sh;
@@ -2771,9 +2778,9 @@ AmbientLightLoader = __decorate([
2771
2778
  * @internal
2772
2779
  */ var AmbientLightContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
2773
2780
  _inherits(AmbientLightContentRestorer, ContentRestorer);
2774
- function AmbientLightContentRestorer(resource, url, requestConfig) {
2781
+ function AmbientLightContentRestorer(resource, remoteUrl, requestConfig) {
2775
2782
  var _this;
2776
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
2783
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
2777
2784
  return _this;
2778
2785
  }
2779
2786
  var _proto = AmbientLightContentRestorer.prototype;
@@ -2783,7 +2790,7 @@ AmbientLightLoader = __decorate([
2783
2790
  var resource = _this.resource;
2784
2791
  var engine = resource.engine;
2785
2792
  engine.resourceManager// @ts-ignore
2786
- ._request(_this.url, _this.requestConfig).then(function(buffer) {
2793
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(buffer) {
2787
2794
  var header = FileHeader.decode(buffer);
2788
2795
  var dataOffset = header.headerLength;
2789
2796
  var textureOffset = dataOffset + AmbientLightLoader._shByteLength;
@@ -2840,7 +2847,10 @@ var FontLoader = /*#__PURE__*/ function(Loader) {
2840
2847
  })).then(function(data) {
2841
2848
  var fontName = data.fontName, fontUrl = data.fontUrl;
2842
2849
  if (fontUrl) {
2843
- _this._registerFont(fontName, fontUrl).then(function() {
2850
+ var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(item.url, fontUrl);
2851
+ // @ts-ignore
2852
+ var remoteUrl = resourceManager._getRemoteUrl(absoluteUrl);
2853
+ _this._registerFont(fontName, remoteUrl).then(function() {
2844
2854
  var font = new engineCore.Font(resourceManager.engine, fontName);
2845
2855
  resolve(font);
2846
2856
  }).catch(function(e) {
@@ -3093,9 +3103,9 @@ function getMeshoptDecoder() {
3093
3103
  }
3094
3104
  var _proto = GLTFResource.prototype;
3095
3105
  /**
3096
- * Instantiate scene root entity.
3097
- * @param sceneIndex - Scene index
3098
- * @returns Root entity
3106
+ * Instantiate a glTF scene root Entity.
3107
+ * @param sceneIndex - The scene index
3108
+ * @returns A detached scene-root instance that must be added to a parent Entity or Scene to update and render
3099
3109
  */ _proto.instantiateSceneRoot = function instantiateSceneRoot(sceneIndex) {
3100
3110
  var sceneRoot = sceneIndex === undefined ? this._defaultSceneRoot : this._sceneRoots[sceneIndex];
3101
3111
  return sceneRoot.clone();
@@ -3334,6 +3344,8 @@ function getMeshoptDecoder() {
3334
3344
  detail.total = total;
3335
3345
  _this._setTaskDetailProgress(url, loaded, total);
3336
3346
  };
3347
+ // @ts-expect-error -- internal method is omitted from public declarations
3348
+ this._remoteAssetBaseURL = resourceManager._getRemoteUrl(glTFResource.url);
3337
3349
  this.contentRestorer = new GLTFContentRestorer(glTFResource);
3338
3350
  }
3339
3351
  var _proto = GLTFParserContext.prototype;
@@ -3424,7 +3436,7 @@ function getMeshoptDecoder() {
3424
3436
  var _this_glTFResource, _glTFResourceKey;
3425
3437
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
3426
3438
  } else {
3427
- var url = this.glTFResource.url;
3439
+ var remoteAssetBaseURL = this._remoteAssetBaseURL;
3428
3440
  resource.then(function(item) {
3429
3441
  if (index == undefined) {
3430
3442
  _this.glTFResource[glTFResourceKey] = item;
@@ -3436,15 +3448,15 @@ function getMeshoptDecoder() {
3436
3448
  for(var i = 0, length = item.length; i < length; i++){
3437
3449
  var mesh = item[i];
3438
3450
  // @ts-ignore
3439
- _this.resourceManager._onSubAssetSuccess(url, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
3451
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
3440
3452
  }
3441
3453
  } else {
3442
3454
  // @ts-ignore
3443
- _this.resourceManager._onSubAssetSuccess(url, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
3455
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
3444
3456
  var _this_glTF_scene;
3445
3457
  if (type === 2 && ((_this_glTF_scene = _this.glTF.scene) != null ? _this_glTF_scene : 0) === index) {
3446
3458
  // @ts-ignore
3447
- _this.resourceManager._onSubAssetSuccess(url, "defaultSceneRoot", item);
3459
+ _this.resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "defaultSceneRoot", item);
3448
3460
  }
3449
3461
  }
3450
3462
  }).catch(function(e) {
@@ -4482,16 +4494,16 @@ exports.GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
4482
4494
  _proto._parseSingleBuffer = function _parseSingleBuffer(context, bufferInfo) {
4483
4495
  var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer, resourceManager = context.resourceManager;
4484
4496
  var url = glTFResource.url;
4497
+ var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(url, bufferInfo.uri);
4485
4498
  // @ts-ignore
4486
- var remoteUrl = resourceManager._getRemoteUrl(url);
4499
+ var remoteUrl = resourceManager._getRemoteUrl(absoluteUrl);
4487
4500
  var restoreBufferRequests = contentRestorer.bufferRequests;
4488
4501
  var requestConfig = {
4489
4502
  type: "arraybuffer"
4490
4503
  };
4491
- var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(remoteUrl, bufferInfo.uri);
4492
- restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
4504
+ restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig));
4493
4505
  var promise = resourceManager// @ts-ignore
4494
- ._requestByRemoteUrl(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
4506
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(undefined, context._onTaskDetail);
4495
4507
  context._addTaskCompletePromise(promise);
4496
4508
  return promise;
4497
4509
  };
@@ -5709,12 +5721,14 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
5709
5721
  }
5710
5722
  var _proto = KTXLoader.prototype;
5711
5723
  _proto.load = function load(item, resourceManager) {
5724
+ // @ts-expect-error -- internal method is omitted from public declarations
5725
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
5712
5726
  var requestConfig = _extends({}, item, {
5713
5727
  type: "arraybuffer"
5714
5728
  });
5715
5729
  return new engineCore.AssetPromise(function(resolve, reject) {
5716
5730
  resourceManager// @ts-ignore
5717
- ._request(item.url, requestConfig).then(function(bin) {
5731
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(bin) {
5718
5732
  var parsedData = parseSingleKTX(bin);
5719
5733
  var width = parsedData.width, height = parsedData.height, mipmaps = parsedData.mipmaps, engineFormat = parsedData.engineFormat;
5720
5734
  var mipmap = mipmaps.length > 1;
@@ -5723,7 +5737,7 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
5723
5737
  var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
5724
5738
  texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
5725
5739
  }
5726
- resourceManager.addContentRestorer(new KTXContentRestorer(texture, item.url, requestConfig));
5740
+ resourceManager.addContentRestorer(new KTXContentRestorer(texture, remoteUrl, requestConfig));
5727
5741
  resolve(texture);
5728
5742
  }).catch(function(e) {
5729
5743
  reject(e);
@@ -5739,9 +5753,9 @@ KTXLoader = __decorate([
5739
5753
  ], KTXLoader);
5740
5754
  var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5741
5755
  _inherits(KTXContentRestorer, ContentRestorer);
5742
- function KTXContentRestorer(resource, url, requestConfig) {
5756
+ function KTXContentRestorer(resource, remoteUrl, requestConfig) {
5743
5757
  var _this;
5744
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
5758
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
5745
5759
  return _this;
5746
5760
  }
5747
5761
  var _proto = KTXContentRestorer.prototype;
@@ -5751,7 +5765,7 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5751
5765
  var engine = resource.engine;
5752
5766
  return new engineCore.AssetPromise(function(resolve, reject) {
5753
5767
  engine.resourceManager// @ts-ignore
5754
- ._request(_this.url, _this.requestConfig).then(function(bin) {
5768
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(bin) {
5755
5769
  var mipmaps = parseSingleKTX(bin).mipmaps;
5756
5770
  for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
5757
5771
  var _mipmaps_miplevel = mipmaps[miplevel], width = _mipmaps_miplevel.width, height = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
@@ -5862,13 +5876,14 @@ var MeshLoader = /*#__PURE__*/ function(Loader) {
5862
5876
  var requestConfig = _extends({}, item, {
5863
5877
  type: "arraybuffer"
5864
5878
  });
5865
- var url = item.url;
5879
+ // @ts-expect-error -- internal method is omitted from public declarations
5880
+ var remoteUrl = resourceManager._getRemoteUrl(item.url);
5866
5881
  return new engineCore.AssetPromise(function(resolve, reject) {
5867
5882
  resourceManager// @ts-ignore
5868
- ._request(url, requestConfig).then(function(data) {
5883
+ ._requestByRemoteUrl(remoteUrl, requestConfig).then(function(data) {
5869
5884
  return decode(data, resourceManager.engine);
5870
5885
  }).then(function(mesh) {
5871
- resourceManager.addContentRestorer(new MeshContentRestorer(mesh, url, requestConfig));
5886
+ resourceManager.addContentRestorer(new MeshContentRestorer(mesh, remoteUrl, requestConfig));
5872
5887
  resolve(mesh);
5873
5888
  }).catch(reject);
5874
5889
  });
@@ -5882,9 +5897,9 @@ MeshLoader = __decorate([
5882
5897
  ], MeshLoader);
5883
5898
  var MeshContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5884
5899
  _inherits(MeshContentRestorer, ContentRestorer);
5885
- function MeshContentRestorer(resource, url, requestConfig) {
5900
+ function MeshContentRestorer(resource, remoteUrl, requestConfig) {
5886
5901
  var _this;
5887
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
5902
+ _this = ContentRestorer.call(this, resource) || this, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
5888
5903
  return _this;
5889
5904
  }
5890
5905
  var _proto = MeshContentRestorer.prototype;
@@ -5894,7 +5909,7 @@ var MeshContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5894
5909
  var engine = resource.engine;
5895
5910
  return new engineCore.AssetPromise(function(resolve, reject) {
5896
5911
  engine.resourceManager// @ts-ignore
5897
- ._request(_this.url, _this.requestConfig).then(function(data) {
5912
+ ._requestByRemoteUrl(_this.remoteUrl, _this.requestConfig).then(function(data) {
5898
5913
  return decode(data, engine, resource);
5899
5914
  }).then(function(mesh) {
5900
5915
  resolve(mesh);
@@ -6200,14 +6215,16 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6200
6215
  _proto.load = function load(item, resourceManager) {
6201
6216
  var _this = this;
6202
6217
  var url = item.url;
6218
+ // @ts-expect-error -- internal method is omitted from public declarations
6219
+ var remoteUrl = resourceManager._getRemoteUrl(url);
6203
6220
  var requestConfig = _extends({}, item, {
6204
6221
  type: "arraybuffer"
6205
6222
  });
6206
6223
  return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
6207
6224
  resourceManager// @ts-ignore
6208
- ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
6225
+ ._requestByRemoteUrl(remoteUrl, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
6209
6226
  _this._decode(buffer, item, resourceManager).then(function(texture) {
6210
- resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
6227
+ resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, remoteUrl, requestConfig));
6211
6228
  resolve(texture);
6212
6229
  }, reject);
6213
6230
  }).catch(reject);
@@ -6244,29 +6261,17 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6244
6261
  };
6245
6262
  _proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
6246
6263
  var _this = this;
6247
- return new engineCore.AssetPromise(function(resolve, reject) {
6248
- var blob = new Blob([
6249
- buffer
6250
- ]);
6251
- var img = new Image();
6252
- img.onload = function() {
6253
- URL.revokeObjectURL(img.src);
6254
- var _item_params;
6255
- var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.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;
6256
- var engine = resourceManager.engine;
6257
- var width = img.width, height = img.height;
6258
- var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
6259
- var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
6260
- texture.setImageSource(img);
6261
- generateMipmap && texture.generateMipmaps();
6262
- _this._applyParams(texture, item);
6263
- resolve(texture);
6264
- };
6265
- img.onerror = function(e) {
6266
- URL.revokeObjectURL(img.src);
6267
- reject(e);
6268
- };
6269
- img.src = URL.createObjectURL(blob);
6264
+ return decodeImage(buffer, item.url).then(function(img) {
6265
+ var _item_params;
6266
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.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;
6267
+ var engine = resourceManager.engine;
6268
+ var width = img.width, height = img.height;
6269
+ var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
6270
+ var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
6271
+ texture.setImageSource(img);
6272
+ generateMipmap && texture.generateMipmaps();
6273
+ _this._applyParams(texture, item);
6274
+ return texture;
6270
6275
  });
6271
6276
  };
6272
6277
  _proto._applyParams = function _applyParams(texture, item) {
@@ -6295,16 +6300,16 @@ TextureLoader = __decorate([
6295
6300
  ], TextureLoader);
6296
6301
  var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6297
6302
  _inherits(TextureContentRestorer, ContentRestorer);
6298
- function TextureContentRestorer(resource, url, requestConfig) {
6303
+ function TextureContentRestorer(resource, url, remoteUrl, requestConfig) {
6299
6304
  var _this;
6300
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
6305
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.remoteUrl = remoteUrl, _this.requestConfig = requestConfig;
6301
6306
  return _this;
6302
6307
  }
6303
6308
  var _proto = TextureContentRestorer.prototype;
6304
6309
  _proto.restoreContent = function restoreContent() {
6305
6310
  var _this = this;
6306
6311
  return this.resource.engine.resourceManager// @ts-ignore
6307
- ._request(this.url, this.requestConfig).then(function(buffer) {
6312
+ ._requestByRemoteUrl(this.remoteUrl, this.requestConfig).then(function(buffer) {
6308
6313
  if (FileHeader.checkMagic(buffer)) {
6309
6314
  return decode(buffer, _this.resource.engine, _this.resource);
6310
6315
  }
@@ -6316,27 +6321,35 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6316
6321
  texture.mipmapCount > 1 && texture.generateMipmaps();
6317
6322
  return texture;
6318
6323
  }
6319
- return new engineCore.AssetPromise(function(resolve, reject) {
6320
- var blob = new Blob([
6321
- buffer
6322
- ]);
6323
- var img = new Image();
6324
- img.onload = function() {
6325
- URL.revokeObjectURL(img.src);
6326
- texture.setImageSource(img);
6327
- texture.mipmapCount > 1 && texture.generateMipmaps();
6328
- resolve(texture);
6329
- };
6330
- img.onerror = function(e) {
6331
- URL.revokeObjectURL(img.src);
6332
- reject(e);
6333
- };
6334
- img.src = URL.createObjectURL(blob);
6324
+ return decodeImage(buffer, _this.url).then(function(img) {
6325
+ texture.setImageSource(img);
6326
+ texture.mipmapCount > 1 && texture.generateMipmaps();
6327
+ return texture;
6335
6328
  });
6336
6329
  });
6337
6330
  };
6338
6331
  return TextureContentRestorer;
6339
6332
  }(engineCore.ContentRestorer);
6333
+ function decodeImage(buffer, url) {
6334
+ return new engineCore.AssetPromise(function(resolve, reject) {
6335
+ var objectUrl = URL.createObjectURL(new Blob([
6336
+ buffer
6337
+ ]));
6338
+ var image = new Image();
6339
+ var releaseObjectUrl = function() {
6340
+ return URL.revokeObjectURL(objectUrl);
6341
+ };
6342
+ image.onload = function() {
6343
+ releaseObjectUrl();
6344
+ resolve(image);
6345
+ };
6346
+ image.onerror = function() {
6347
+ releaseObjectUrl();
6348
+ reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + buffer.byteLength + " bytes)."));
6349
+ };
6350
+ image.src = objectUrl;
6351
+ });
6352
+ }
6340
6353
 
6341
6354
  var AudioLoader = /*#__PURE__*/ function(Loader) {
6342
6355
  _inherits(AudioLoader, Loader);
@@ -6453,8 +6466,10 @@ var RenderTargetLoader = /*#__PURE__*/ function(Loader) {
6453
6466
  var _proto = RenderTargetLoader.prototype;
6454
6467
  _proto.load = function load(item, resourceManager) {
6455
6468
  var engine = resourceManager.engine;
6469
+ // @ts-expect-error -- internal method is omitted from public declarations
6470
+ var remoteAssetBaseURL = resourceManager._getRemoteUrl(item.url);
6456
6471
  return resourceManager// @ts-ignore
6457
- ._request(item.url, _extends({}, item, {
6472
+ ._requestByRemoteUrl(remoteAssetBaseURL, _extends({}, item, {
6458
6473
  type: "json"
6459
6474
  })).then(function(data) {
6460
6475
  var width = data.width, height = data.height, colorFormats = data.colorFormats, depthFormat = data.depthFormat, antiAliasing = data.antiAliasing, autoGenerateMipmaps = data.autoGenerateMipmaps;
@@ -6480,7 +6495,7 @@ var RenderTargetLoader = /*#__PURE__*/ function(Loader) {
6480
6495
  // Notify pending sub-asset requests for colorTextures
6481
6496
  for(var i = 0, n = colorTextures.length; i < n; i++){
6482
6497
  // @ts-ignore
6483
- resourceManager._onSubAssetSuccess(item.url, "colorTextures[" + i + "]", colorTextures[i]);
6498
+ resourceManager._onSubAssetSuccess(remoteAssetBaseURL, "colorTextures[" + i + "]", colorTextures[i]);
6484
6499
  }
6485
6500
  return rt;
6486
6501
  });