@galacean/engine-loader 2.0.0-alpha.57 → 2.0.0-alpha.58
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 +24 -37
- package/dist/main.js.map +1 -1
- package/dist/module.js +25 -38
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/ImageDecoder.d.ts +4 -3
package/dist/main.js
CHANGED
|
@@ -1207,32 +1207,42 @@ function _instanceof(left, right) {
|
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Decodes encoded image bytes (PNG, JPEG, WebP, ...) into an image element.
|
|
1209
1209
|
*
|
|
1210
|
-
* The blob handed to the image carries the MIME type detected from the bytes:
|
|
1211
|
-
* blob, but some platforms (for example mini-game runtimes) only decode images
|
|
1210
|
+
* The blob handed to the image carries the declared `mimeType` or the MIME type detected from the bytes:
|
|
1211
|
+
* browsers sniff an untyped blob, but some platforms (for example mini-game runtimes) only decode images
|
|
1212
|
+
* whose type is declared.
|
|
1212
1213
|
* @internal
|
|
1213
1214
|
*/ var ImageDecoder = /*#__PURE__*/ function() {
|
|
1214
1215
|
function ImageDecoder() {}
|
|
1215
|
-
ImageDecoder._decode = function _decode(data, url) {
|
|
1216
|
+
ImageDecoder._decode = function _decode(data, url, mimeType) {
|
|
1216
1217
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
1217
1218
|
var objectUrl = URL.createObjectURL(new Blob([
|
|
1218
1219
|
data
|
|
1219
1220
|
], {
|
|
1220
|
-
type: ImageDecoder._getMimeType(data)
|
|
1221
|
+
type: mimeType || ImageDecoder._getMimeType(data)
|
|
1221
1222
|
}));
|
|
1222
1223
|
var image = new Image();
|
|
1223
1224
|
image.onload = function() {
|
|
1224
|
-
|
|
1225
|
-
|
|
1225
|
+
var complete = function() {
|
|
1226
|
+
ImageDecoder._releaseObjectUrl(image, objectUrl);
|
|
1227
|
+
resolve(image);
|
|
1228
|
+
};
|
|
1229
|
+
if ((engineCore.SystemInfo.platform === engineCore.Platform.IPhone || engineCore.SystemInfo.platform === engineCore.Platform.IPad) && typeof requestAnimationFrame !== "undefined") {
|
|
1230
|
+
// Defer on iOS WebKit so the decoded image surface is ready before revoking the blob URL.
|
|
1231
|
+
requestAnimationFrame(complete);
|
|
1232
|
+
} else {
|
|
1233
|
+
complete();
|
|
1234
|
+
}
|
|
1226
1235
|
};
|
|
1227
|
-
image.onerror = function() {
|
|
1236
|
+
image.onerror = image.onabort = function() {
|
|
1228
1237
|
ImageDecoder._releaseObjectUrl(image, objectUrl);
|
|
1229
1238
|
reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + data.byteLength + " bytes)."));
|
|
1230
1239
|
};
|
|
1240
|
+
image.crossOrigin = "anonymous";
|
|
1231
1241
|
image.src = objectUrl;
|
|
1232
1242
|
});
|
|
1233
1243
|
};
|
|
1234
1244
|
ImageDecoder._getMimeType = function _getMimeType(data) {
|
|
1235
|
-
var bytes = _instanceof(data, Uint8Array) ? data : new Uint8Array(data);
|
|
1245
|
+
var bytes = _instanceof(data, Uint8Array) ? data : ArrayBuffer.isView(data) ? new Uint8Array(data.buffer, data.byteOffset, data.byteLength) : new Uint8Array(data);
|
|
1236
1246
|
if (bytes.length >= 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) {
|
|
1237
1247
|
return "image/png";
|
|
1238
1248
|
}
|
|
@@ -1248,6 +1258,7 @@ function _instanceof(left, right) {
|
|
|
1248
1258
|
ImageDecoder._releaseObjectUrl = function _releaseObjectUrl(image, objectUrl) {
|
|
1249
1259
|
image.onload = null;
|
|
1250
1260
|
image.onerror = null;
|
|
1261
|
+
image.onabort = null;
|
|
1251
1262
|
URL.revokeObjectURL(objectUrl);
|
|
1252
1263
|
};
|
|
1253
1264
|
return ImageDecoder;
|
|
@@ -3785,30 +3796,7 @@ function registerGLTFParser(pipeline) {
|
|
|
3785
3796
|
/**
|
|
3786
3797
|
* Load image buffer
|
|
3787
3798
|
*/ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
|
|
3788
|
-
return
|
|
3789
|
-
var blob = new window.Blob([
|
|
3790
|
-
imageBuffer
|
|
3791
|
-
], {
|
|
3792
|
-
type: type
|
|
3793
|
-
});
|
|
3794
|
-
var img = new Image();
|
|
3795
|
-
img.onerror = function() {
|
|
3796
|
-
URL.revokeObjectURL(img.src);
|
|
3797
|
-
reject(new Error("Failed to load image buffer"));
|
|
3798
|
-
};
|
|
3799
|
-
img.onload = function() {
|
|
3800
|
-
// Call requestAnimationFrame to avoid iOS's bug.
|
|
3801
|
-
requestAnimationFrame(function() {
|
|
3802
|
-
URL.revokeObjectURL(img.src);
|
|
3803
|
-
resolve(img);
|
|
3804
|
-
img.onload = null;
|
|
3805
|
-
img.onerror = null;
|
|
3806
|
-
img.onabort = null;
|
|
3807
|
-
});
|
|
3808
|
-
};
|
|
3809
|
-
img.crossOrigin = "anonymous";
|
|
3810
|
-
img.src = URL.createObjectURL(blob);
|
|
3811
|
-
});
|
|
3799
|
+
return Promise.resolve(ImageDecoder._decode(imageBuffer, type, type));
|
|
3812
3800
|
};
|
|
3813
3801
|
/**
|
|
3814
3802
|
* Parse the glb format.
|
|
@@ -3947,7 +3935,7 @@ function registerGLTFParser(pipeline) {
|
|
|
3947
3935
|
}
|
|
3948
3936
|
});
|
|
3949
3937
|
} else {
|
|
3950
|
-
return
|
|
3938
|
+
return ImageDecoder._decode(bufferData, _this.resource.url, textureRestoreInfo.mimeType).then(function(image) {
|
|
3951
3939
|
texture.setImageSource(image);
|
|
3952
3940
|
texture.generateMipmaps();
|
|
3953
3941
|
});
|
|
@@ -5215,8 +5203,9 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5215
5203
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
5216
5204
|
texture = context.get(GLTFParserType.Buffer).then(function(buffers) {
|
|
5217
5205
|
var buffer = buffers[bufferView.buffer];
|
|
5218
|
-
var
|
|
5219
|
-
|
|
5206
|
+
var _bufferView_byteOffset;
|
|
5207
|
+
var imageBuffer = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
|
|
5208
|
+
return ImageDecoder._decode(imageBuffer, imageName || textureName || url, mimeType).then(function(image) {
|
|
5220
5209
|
var width = image.width, height = image.height;
|
|
5221
5210
|
var format = engineCore.TextureFormat.R8G8B8A8;
|
|
5222
5211
|
var _samplerInfo_mipmap;
|
|
@@ -5230,8 +5219,6 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5230
5219
|
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
5231
5220
|
return texture;
|
|
5232
5221
|
});
|
|
5233
|
-
}).catch(function(e) {
|
|
5234
|
-
engineCore.Logger.error("GLTFTextureParser: image buffer error", e);
|
|
5235
5222
|
});
|
|
5236
5223
|
}
|
|
5237
5224
|
return texture;
|