@galacean/engine-loader 2.0.0-alpha.24 → 2.0.0-alpha.25
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 +376 -463
- package/dist/main.js.map +1 -1
- package/dist/module.js +376 -463
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/HDRDecoder.d.ts +27 -8
- package/types/{Texture2DLoader.d.ts → TextureLoader.d.ts} +4 -4
- package/types/index.d.ts +2 -3
- package/types/resource-deserialize/index.d.ts +2 -1
- package/types/resource-deserialize/resources/textureCube/TextureCubeDecoder.d.ts +1 -0
- package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +0 -9
- /package/types/{TextureCubeLoader.d.ts → resource-deserialize/resources/texture2D/Texture2DDecoder.d.ts} +0 -0
package/dist/main.js
CHANGED
|
@@ -949,11 +949,190 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
949
949
|
return ReflectionParser;
|
|
950
950
|
}();
|
|
951
951
|
|
|
952
|
-
|
|
952
|
+
/**
|
|
953
|
+
* HDR (Radiance RGBE) image decoder.
|
|
954
|
+
*
|
|
955
|
+
* Decodes .hdr files into pixel data. Supports parsing the header
|
|
956
|
+
* and decoding RLE-compressed RGBE scanlines into R16G16B16A16 half-float pixels.
|
|
957
|
+
*/ var HDRDecoder = /*#__PURE__*/ function() {
|
|
958
|
+
function HDRDecoder() {}
|
|
959
|
+
/**
|
|
960
|
+
* Parse the header of an HDR file.
|
|
961
|
+
* @returns Header info including width, height, and data start position.
|
|
962
|
+
*/ HDRDecoder.parseHeader = function parseHeader(uint8array) {
|
|
963
|
+
var line = this._readStringLine(uint8array, 0);
|
|
964
|
+
if (line[0] !== "#" || line[1] !== "?") {
|
|
965
|
+
throw "HDRDecoder: invalid file header";
|
|
966
|
+
}
|
|
967
|
+
var endOfHeader = false;
|
|
968
|
+
var findFormat = false;
|
|
969
|
+
var lineIndex = 0;
|
|
970
|
+
do {
|
|
971
|
+
lineIndex += line.length + 1;
|
|
972
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
973
|
+
if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
|
|
974
|
+
else if (line.length === 0) endOfHeader = true;
|
|
975
|
+
}while (!endOfHeader);
|
|
976
|
+
if (!findFormat) {
|
|
977
|
+
throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
|
|
978
|
+
}
|
|
979
|
+
lineIndex += line.length + 1;
|
|
980
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
981
|
+
var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
|
|
982
|
+
if (!match || match.length < 3) {
|
|
983
|
+
throw "HDRDecoder: missing image size, only -Y +X layout is supported";
|
|
984
|
+
}
|
|
985
|
+
var width = parseInt(match[2]);
|
|
986
|
+
var height = parseInt(match[1]);
|
|
987
|
+
if (width < 8 || width > 0x7fff) {
|
|
988
|
+
throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
height: height,
|
|
992
|
+
width: width,
|
|
993
|
+
dataPosition: lineIndex + line.length + 1
|
|
994
|
+
};
|
|
995
|
+
};
|
|
996
|
+
/**
|
|
997
|
+
* Decode an HDR file buffer into R16G16B16A16 half-float pixel data.
|
|
998
|
+
* @param buffer - The full HDR file as Uint8Array.
|
|
999
|
+
* @returns Object with width, height, and half-float pixel data.
|
|
1000
|
+
*/ HDRDecoder.decode = function decode(buffer) {
|
|
1001
|
+
var header = this.parseHeader(buffer);
|
|
1002
|
+
var width = header.width, height = header.height, dataPosition = header.dataPosition;
|
|
1003
|
+
var rgbe = this._readPixels(buffer.subarray(dataPosition), width, height);
|
|
1004
|
+
var pixels = this._rgbeToHalfFloat(rgbe, width, height);
|
|
1005
|
+
return {
|
|
1006
|
+
width: width,
|
|
1007
|
+
height: height,
|
|
1008
|
+
pixels: pixels
|
|
1009
|
+
};
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* Convert RGBE pixel data to R16G16B16A16 half-float.
|
|
1013
|
+
*/ HDRDecoder._rgbeToHalfFloat = function _rgbeToHalfFloat(rgbe, width, height) {
|
|
1014
|
+
var floatView = this._floatView;
|
|
1015
|
+
var uint32View = this._uint32View;
|
|
1016
|
+
var _this__float2HalfTables = this._float2HalfTables, baseTable = _this__float2HalfTables.baseTable, shiftTable = _this__float2HalfTables.shiftTable;
|
|
1017
|
+
var one = 0x3c00; // Half float 1.0
|
|
1018
|
+
var pixelCount = width * height;
|
|
1019
|
+
var result = new Uint16Array(pixelCount * 4);
|
|
1020
|
+
for(var i = 0; i < pixelCount; i++){
|
|
1021
|
+
var srcIdx = i * 4;
|
|
1022
|
+
var dstIdx = i * 4;
|
|
1023
|
+
var scaleFactor = Math.pow(2, rgbe[srcIdx + 3] - 128 - 8);
|
|
1024
|
+
for(var c = 0; c < 3; c++){
|
|
1025
|
+
floatView[0] = Math.min(rgbe[srcIdx + c] * scaleFactor, 65504);
|
|
1026
|
+
var f = uint32View[0];
|
|
1027
|
+
var e = f >> 23 & 0x1ff;
|
|
1028
|
+
result[dstIdx + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
|
|
1029
|
+
}
|
|
1030
|
+
result[dstIdx + 3] = one;
|
|
1031
|
+
}
|
|
1032
|
+
return result;
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* Decode RLE-compressed RGBE scanlines into raw RGBE pixel data.
|
|
1036
|
+
*/ HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
|
|
1037
|
+
var byteLength = buffer.byteLength;
|
|
1038
|
+
var dataRGBA = new Uint8Array(4 * width * height);
|
|
1039
|
+
var offset = 0;
|
|
1040
|
+
var pos = 0;
|
|
1041
|
+
var ptrEnd = 4 * width;
|
|
1042
|
+
var scanLineBuffer = new Uint8Array(ptrEnd);
|
|
1043
|
+
var numScanLines = height;
|
|
1044
|
+
while(numScanLines > 0 && pos < byteLength){
|
|
1045
|
+
var a = buffer[pos++];
|
|
1046
|
+
var b = buffer[pos++];
|
|
1047
|
+
var c = buffer[pos++];
|
|
1048
|
+
var d = buffer[pos++];
|
|
1049
|
+
if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
|
|
1050
|
+
if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
|
|
1051
|
+
var ptr = 0;
|
|
1052
|
+
while(ptr < ptrEnd && pos < byteLength){
|
|
1053
|
+
var count = buffer[pos++];
|
|
1054
|
+
var isEncodedRun = count > 128;
|
|
1055
|
+
if (isEncodedRun) count -= 128;
|
|
1056
|
+
if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
|
|
1057
|
+
if (isEncodedRun) {
|
|
1058
|
+
var byteValue = buffer[pos++];
|
|
1059
|
+
for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
|
|
1060
|
+
} else {
|
|
1061
|
+
scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
|
|
1062
|
+
ptr += count;
|
|
1063
|
+
pos += count;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
for(var i1 = 0; i1 < width; i1++, offset += 4){
|
|
1067
|
+
dataRGBA[offset] = scanLineBuffer[i1];
|
|
1068
|
+
dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
|
|
1069
|
+
dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
|
|
1070
|
+
dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
|
|
1071
|
+
}
|
|
1072
|
+
numScanLines--;
|
|
1073
|
+
}
|
|
1074
|
+
return dataRGBA;
|
|
1075
|
+
};
|
|
1076
|
+
HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
|
|
1077
|
+
var baseTable = new Uint32Array(512);
|
|
1078
|
+
var shiftTable = new Uint32Array(512);
|
|
1079
|
+
for(var i = 0; i < 256; ++i){
|
|
1080
|
+
var e = i - 127;
|
|
1081
|
+
if (e < -27) {
|
|
1082
|
+
baseTable[i] = 0x0000;
|
|
1083
|
+
baseTable[i | 0x100] = 0x8000;
|
|
1084
|
+
shiftTable[i] = 24;
|
|
1085
|
+
shiftTable[i | 0x100] = 24;
|
|
1086
|
+
} else if (e < -14) {
|
|
1087
|
+
baseTable[i] = 0x0400 >> -e - 14;
|
|
1088
|
+
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
1089
|
+
shiftTable[i] = -e - 1;
|
|
1090
|
+
shiftTable[i | 0x100] = -e - 1;
|
|
1091
|
+
} else if (e <= 15) {
|
|
1092
|
+
baseTable[i] = e + 15 << 10;
|
|
1093
|
+
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
1094
|
+
shiftTable[i] = 13;
|
|
1095
|
+
shiftTable[i | 0x100] = 13;
|
|
1096
|
+
} else if (e < 128) {
|
|
1097
|
+
baseTable[i] = 0x7c00;
|
|
1098
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
1099
|
+
shiftTable[i] = 24;
|
|
1100
|
+
shiftTable[i | 0x100] = 24;
|
|
1101
|
+
} else {
|
|
1102
|
+
baseTable[i] = 0x7c00;
|
|
1103
|
+
baseTable[i | 0x100] = 0xfc00;
|
|
1104
|
+
shiftTable[i] = 13;
|
|
1105
|
+
shiftTable[i | 0x100] = 13;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
baseTable: baseTable,
|
|
1110
|
+
shiftTable: shiftTable
|
|
1111
|
+
};
|
|
1112
|
+
};
|
|
1113
|
+
HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
|
|
1114
|
+
var line = "";
|
|
1115
|
+
for(var i = startIndex, n = uint8array.length; i < n; i++){
|
|
1116
|
+
var character = String.fromCharCode(uint8array[i]);
|
|
1117
|
+
if (character === "\n") break;
|
|
1118
|
+
line += character;
|
|
1119
|
+
}
|
|
1120
|
+
return line;
|
|
1121
|
+
};
|
|
1122
|
+
return HDRDecoder;
|
|
1123
|
+
}();
|
|
1124
|
+
HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
1125
|
+
HDRDecoder._floatView = new Float32Array(1);
|
|
1126
|
+
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
|
|
1130
|
+
* [format(1B)] [width(2B)] [height(2B)] [isSRGBColorSpace(1B)] [Uint32(imageSize) + imageBytes]
|
|
1131
|
+
*/ var Texture2DDecoder = /*#__PURE__*/ function() {
|
|
953
1132
|
function Texture2DDecoder() {}
|
|
954
1133
|
Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
955
1134
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
956
|
-
|
|
1135
|
+
bufferReader.nextStr();
|
|
957
1136
|
var mipmap = !!bufferReader.nextUint8();
|
|
958
1137
|
var filterMode = bufferReader.nextUint8();
|
|
959
1138
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -962,58 +1141,34 @@ exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
|
962
1141
|
var format = bufferReader.nextUint8();
|
|
963
1142
|
var width = bufferReader.nextUint16();
|
|
964
1143
|
var height = bufferReader.nextUint16();
|
|
965
|
-
var isPixelBuffer = bufferReader.nextUint8();
|
|
966
1144
|
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
967
|
-
var
|
|
968
|
-
var
|
|
969
|
-
var
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
var pixelBuffer1 = imagesData[i];
|
|
981
|
-
texture2D.setPixelBuffer(pixelBuffer1, i);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
// @ts-ignore
|
|
985
|
-
engine.resourceManager._objectPool[url] = texture2D;
|
|
986
|
-
resolve(texture2D);
|
|
1145
|
+
var imageData = bufferReader.nextImagesData(1)[0];
|
|
1146
|
+
var isHDR = imageData[0] === 0x23 && imageData[1] === 0x3f;
|
|
1147
|
+
var textureFormat = isHDR ? engineCore.TextureFormat.R16G16B16A16 : format;
|
|
1148
|
+
var texture = restoredTexture || new engineCore.Texture2D(engine, width, height, textureFormat, mipmap, isHDR ? false : isSRGBColorSpace);
|
|
1149
|
+
texture.filterMode = filterMode;
|
|
1150
|
+
texture.anisoLevel = anisoLevel;
|
|
1151
|
+
texture.wrapModeU = wrapModeU;
|
|
1152
|
+
texture.wrapModeV = wrapModeV;
|
|
1153
|
+
if (isHDR) {
|
|
1154
|
+
var pixels = HDRDecoder.decode(imageData).pixels;
|
|
1155
|
+
texture.setPixelBuffer(pixels);
|
|
1156
|
+
mipmap && texture.generateMipmaps();
|
|
1157
|
+
resolve(texture);
|
|
987
1158
|
} else {
|
|
988
|
-
var blob = new
|
|
989
|
-
|
|
1159
|
+
var blob = new Blob([
|
|
1160
|
+
imageData
|
|
990
1161
|
]);
|
|
991
1162
|
var img = new Image();
|
|
992
1163
|
img.onload = function() {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
onComplete();
|
|
1002
|
-
if (mipmap) {
|
|
1003
|
-
var _loop = function(i) {
|
|
1004
|
-
var blob = new window.Blob([
|
|
1005
|
-
imagesData[i]
|
|
1006
|
-
]);
|
|
1007
|
-
var img = new Image();
|
|
1008
|
-
img.onload = function() {
|
|
1009
|
-
texture2D.setImageSource(img, i);
|
|
1010
|
-
onComplete();
|
|
1011
|
-
};
|
|
1012
|
-
img.src = URL.createObjectURL(blob);
|
|
1013
|
-
};
|
|
1014
|
-
texture2D.generateMipmaps();
|
|
1015
|
-
for(var i = 1; i < mipCount; i++)_loop(i);
|
|
1016
|
-
}
|
|
1164
|
+
URL.revokeObjectURL(img.src);
|
|
1165
|
+
texture.setImageSource(img);
|
|
1166
|
+
mipmap && texture.generateMipmaps();
|
|
1167
|
+
resolve(texture);
|
|
1168
|
+
};
|
|
1169
|
+
img.onerror = function(e) {
|
|
1170
|
+
URL.revokeObjectURL(img.src);
|
|
1171
|
+
reject(e);
|
|
1017
1172
|
};
|
|
1018
1173
|
img.src = URL.createObjectURL(blob);
|
|
1019
1174
|
}
|
|
@@ -1021,9 +1176,72 @@ exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
|
1021
1176
|
};
|
|
1022
1177
|
return Texture2DDecoder;
|
|
1023
1178
|
}();
|
|
1024
|
-
|
|
1179
|
+
Texture2DDecoder = __decorate([
|
|
1025
1180
|
decoder("Texture2D")
|
|
1026
|
-
],
|
|
1181
|
+
], Texture2DDecoder);
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
|
|
1185
|
+
* [format(1B)] [faceSize(2B)] [isSRGBColorSpace(1B)] [Uint32(size) + faceBytes] × 6
|
|
1186
|
+
*/ var TextureCubeDecoder = /*#__PURE__*/ function() {
|
|
1187
|
+
function TextureCubeDecoder() {}
|
|
1188
|
+
TextureCubeDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1189
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
1190
|
+
bufferReader.nextStr();
|
|
1191
|
+
var mipmap = !!bufferReader.nextUint8();
|
|
1192
|
+
var filterMode = bufferReader.nextUint8();
|
|
1193
|
+
var anisoLevel = bufferReader.nextUint8();
|
|
1194
|
+
var wrapModeU = bufferReader.nextUint8();
|
|
1195
|
+
var wrapModeV = bufferReader.nextUint8();
|
|
1196
|
+
var format = bufferReader.nextUint8();
|
|
1197
|
+
var faceSize = bufferReader.nextUint16();
|
|
1198
|
+
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
1199
|
+
var facesData = bufferReader.nextImagesData(6);
|
|
1200
|
+
// Detect format by first face's magic bytes
|
|
1201
|
+
var isHDR = facesData[0][0] === 0x23 && facesData[0][1] === 0x3f;
|
|
1202
|
+
var textureFormat = isHDR ? engineCore.TextureFormat.R16G16B16A16 : format;
|
|
1203
|
+
var texture = restoredTexture || new engineCore.TextureCube(engine, faceSize, textureFormat, mipmap, isSRGBColorSpace);
|
|
1204
|
+
texture.filterMode = filterMode;
|
|
1205
|
+
texture.anisoLevel = anisoLevel;
|
|
1206
|
+
texture.wrapModeU = wrapModeU;
|
|
1207
|
+
texture.wrapModeV = wrapModeV;
|
|
1208
|
+
if (isHDR) {
|
|
1209
|
+
for(var i = 0; i < 6; i++){
|
|
1210
|
+
var pixels = HDRDecoder.decode(facesData[i]).pixels;
|
|
1211
|
+
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + i, pixels, 0);
|
|
1212
|
+
}
|
|
1213
|
+
mipmap && texture.generateMipmaps();
|
|
1214
|
+
resolve(texture);
|
|
1215
|
+
} else {
|
|
1216
|
+
var _loop = function(i1) {
|
|
1217
|
+
var blob = new Blob([
|
|
1218
|
+
facesData[i1]
|
|
1219
|
+
]);
|
|
1220
|
+
var img = new Image();
|
|
1221
|
+
img.onload = function() {
|
|
1222
|
+
URL.revokeObjectURL(img.src);
|
|
1223
|
+
texture.setImageSource(engineCore.TextureCubeFace.PositiveX + i1, img);
|
|
1224
|
+
if (++loadedCount === 6) {
|
|
1225
|
+
mipmap && texture.generateMipmaps();
|
|
1226
|
+
resolve(texture);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
img.onerror = function(e) {
|
|
1230
|
+
URL.revokeObjectURL(img.src);
|
|
1231
|
+
reject(e);
|
|
1232
|
+
};
|
|
1233
|
+
img.src = URL.createObjectURL(blob);
|
|
1234
|
+
};
|
|
1235
|
+
var loadedCount = 0;
|
|
1236
|
+
for(var i1 = 0; i1 < 6; i1++)_loop(i1);
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
};
|
|
1240
|
+
return TextureCubeDecoder;
|
|
1241
|
+
}();
|
|
1242
|
+
TextureCubeDecoder = __decorate([
|
|
1243
|
+
decoder("TextureCube")
|
|
1244
|
+
], TextureCubeDecoder);
|
|
1027
1245
|
|
|
1028
1246
|
function _instanceof(left, right) {
|
|
1029
1247
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -3631,11 +3849,13 @@ function registerGLTFParser(pipeline) {
|
|
|
3631
3849
|
});
|
|
3632
3850
|
var img = new Image();
|
|
3633
3851
|
img.onerror = function() {
|
|
3852
|
+
URL.revokeObjectURL(img.src);
|
|
3634
3853
|
reject(new Error("Failed to load image buffer"));
|
|
3635
3854
|
};
|
|
3636
3855
|
img.onload = function() {
|
|
3637
3856
|
// Call requestAnimationFrame to avoid iOS's bug.
|
|
3638
3857
|
requestAnimationFrame(function() {
|
|
3858
|
+
URL.revokeObjectURL(img.src);
|
|
3639
3859
|
resolve(img);
|
|
3640
3860
|
img.onload = null;
|
|
3641
3861
|
img.onerror = null;
|
|
@@ -5065,7 +5285,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5065
5285
|
if (uri) {
|
|
5066
5286
|
var extIndex = uri.lastIndexOf(".");
|
|
5067
5287
|
var ext = uri.substring(extIndex + 1);
|
|
5068
|
-
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.
|
|
5288
|
+
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture;
|
|
5069
5289
|
texture = engine.resourceManager.load({
|
|
5070
5290
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
5071
5291
|
type: type,
|
|
@@ -5941,7 +6161,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5941
6161
|
var _atlasItem_type;
|
|
5942
6162
|
chainPromises.push(resourceManager.load({
|
|
5943
6163
|
url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
5944
|
-
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.
|
|
6164
|
+
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.Texture,
|
|
5945
6165
|
params: {
|
|
5946
6166
|
format: format,
|
|
5947
6167
|
mipmap: mipmap
|
|
@@ -6079,26 +6299,12 @@ TextLoader = __decorate([
|
|
|
6079
6299
|
])
|
|
6080
6300
|
], TextLoader);
|
|
6081
6301
|
|
|
6082
|
-
function
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
buffer
|
|
6086
|
-
]);
|
|
6087
|
-
var img = new Image();
|
|
6088
|
-
img.onload = function() {
|
|
6089
|
-
URL.revokeObjectURL(img.src);
|
|
6090
|
-
resolve(img);
|
|
6091
|
-
};
|
|
6092
|
-
img.onerror = reject;
|
|
6093
|
-
img.src = URL.createObjectURL(blob);
|
|
6094
|
-
});
|
|
6095
|
-
}
|
|
6096
|
-
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
6097
|
-
_inherits(Texture2DLoader, Loader);
|
|
6098
|
-
function Texture2DLoader() {
|
|
6302
|
+
var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
6303
|
+
_inherits(TextureLoader, Loader);
|
|
6304
|
+
function TextureLoader() {
|
|
6099
6305
|
return Loader.apply(this, arguments) || this;
|
|
6100
6306
|
}
|
|
6101
|
-
var _proto =
|
|
6307
|
+
var _proto = TextureLoader.prototype;
|
|
6102
6308
|
_proto.load = function load(item, resourceManager) {
|
|
6103
6309
|
var _this = this;
|
|
6104
6310
|
var url = item.url;
|
|
@@ -6108,429 +6314,136 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6108
6314
|
return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
|
|
6109
6315
|
resourceManager// @ts-ignore
|
|
6110
6316
|
._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
}, reject);
|
|
6116
|
-
} else {
|
|
6117
|
-
loadImageFromBuffer(buffer).then(function(img) {
|
|
6118
|
-
var texture = _this._createTexture(img, item, resourceManager);
|
|
6119
|
-
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
6120
|
-
resolve(texture);
|
|
6121
|
-
}, reject);
|
|
6122
|
-
}
|
|
6317
|
+
_this._decode(buffer, item, resourceManager).then(function(texture) {
|
|
6318
|
+
resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
|
|
6319
|
+
resolve(texture);
|
|
6320
|
+
}, reject);
|
|
6123
6321
|
}).catch(reject);
|
|
6124
6322
|
});
|
|
6125
6323
|
};
|
|
6126
|
-
_proto.
|
|
6324
|
+
_proto._decode = function _decode(buffer, item, resourceManager) {
|
|
6325
|
+
if (FileHeader.checkMagic(buffer)) {
|
|
6326
|
+
return decode(buffer, resourceManager.engine);
|
|
6327
|
+
}
|
|
6328
|
+
var bufferView = new Uint8Array(buffer);
|
|
6329
|
+
var isHDR = bufferView[0] === 0x23 && bufferView[1] === 0x3f;
|
|
6330
|
+
if (isHDR) {
|
|
6331
|
+
return this._decodeHDR(bufferView, item, resourceManager);
|
|
6332
|
+
}
|
|
6333
|
+
return this._decodeImage(buffer, item, resourceManager);
|
|
6334
|
+
};
|
|
6335
|
+
_proto._decodeHDR = function _decodeHDR(buffer, item, resourceManager) {
|
|
6336
|
+
var _this = this;
|
|
6337
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6338
|
+
var engine = resourceManager.engine;
|
|
6339
|
+
if (!engineCore.SystemInfo.supportsTextureFormat(engine, engineCore.TextureFormat.R16G16B16A16)) {
|
|
6340
|
+
reject(new Error("TextureLoader: HDR texture requires half float support."));
|
|
6341
|
+
return;
|
|
6342
|
+
}
|
|
6343
|
+
var _HDRDecoder_decode = HDRDecoder.decode(buffer), width = _HDRDecoder_decode.width, height = _HDRDecoder_decode.height, pixels = _HDRDecoder_decode.pixels;
|
|
6344
|
+
var _item_params;
|
|
6345
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
6346
|
+
var texture = new engineCore.Texture2D(engine, width, height, engineCore.TextureFormat.R16G16B16A16, mipmap, false);
|
|
6347
|
+
texture.setPixelBuffer(pixels);
|
|
6348
|
+
mipmap && texture.generateMipmaps();
|
|
6349
|
+
_this._applyParams(texture, item);
|
|
6350
|
+
resolve(texture);
|
|
6351
|
+
});
|
|
6352
|
+
};
|
|
6353
|
+
_proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
|
|
6354
|
+
var _this = this;
|
|
6355
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6356
|
+
var blob = new Blob([
|
|
6357
|
+
buffer
|
|
6358
|
+
]);
|
|
6359
|
+
var img = new Image();
|
|
6360
|
+
img.onload = function() {
|
|
6361
|
+
URL.revokeObjectURL(img.src);
|
|
6362
|
+
var _item_params;
|
|
6363
|
+
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;
|
|
6364
|
+
var engine = resourceManager.engine;
|
|
6365
|
+
var width = img.width, height = img.height;
|
|
6366
|
+
var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6367
|
+
var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6368
|
+
texture.setImageSource(img);
|
|
6369
|
+
generateMipmap && texture.generateMipmaps();
|
|
6370
|
+
_this._applyParams(texture, item);
|
|
6371
|
+
resolve(texture);
|
|
6372
|
+
};
|
|
6373
|
+
img.onerror = function(e) {
|
|
6374
|
+
URL.revokeObjectURL(img.src);
|
|
6375
|
+
reject(e);
|
|
6376
|
+
};
|
|
6377
|
+
img.src = URL.createObjectURL(blob);
|
|
6378
|
+
});
|
|
6379
|
+
};
|
|
6380
|
+
_proto._applyParams = function _applyParams(texture, item) {
|
|
6127
6381
|
var _item_params;
|
|
6128
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {},
|
|
6129
|
-
var width = img.width, height = img.height;
|
|
6130
|
-
var engine = resourceManager.engine;
|
|
6131
|
-
var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6132
|
-
var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6382
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6133
6383
|
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6134
6384
|
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6135
6385
|
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6136
6386
|
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6137
|
-
texture.setImageSource(img);
|
|
6138
|
-
generateMipmap && texture.generateMipmaps();
|
|
6139
6387
|
var url = item.url;
|
|
6140
6388
|
if (url.indexOf("data:") !== 0) {
|
|
6141
6389
|
texture.name = url.substring(url.lastIndexOf("/") + 1);
|
|
6142
6390
|
}
|
|
6143
|
-
return texture;
|
|
6144
6391
|
};
|
|
6145
|
-
return
|
|
6392
|
+
return TextureLoader;
|
|
6146
6393
|
}(engineCore.Loader);
|
|
6147
|
-
|
|
6148
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
6394
|
+
TextureLoader = __decorate([
|
|
6395
|
+
engineCore.resourceLoader(engineCore.AssetType.Texture, [
|
|
6396
|
+
"tex",
|
|
6149
6397
|
"png",
|
|
6150
6398
|
"jpg",
|
|
6151
6399
|
"webp",
|
|
6152
6400
|
"jpeg",
|
|
6153
|
-
"
|
|
6401
|
+
"hdr"
|
|
6154
6402
|
])
|
|
6155
|
-
],
|
|
6156
|
-
var
|
|
6157
|
-
_inherits(
|
|
6158
|
-
function
|
|
6403
|
+
], TextureLoader);
|
|
6404
|
+
var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6405
|
+
_inherits(TextureContentRestorer, ContentRestorer);
|
|
6406
|
+
function TextureContentRestorer(resource, url, requestConfig) {
|
|
6159
6407
|
var _this;
|
|
6160
6408
|
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6161
6409
|
return _this;
|
|
6162
6410
|
}
|
|
6163
|
-
var _proto =
|
|
6411
|
+
var _proto = TextureContentRestorer.prototype;
|
|
6164
6412
|
_proto.restoreContent = function restoreContent() {
|
|
6165
|
-
var
|
|
6166
|
-
|
|
6167
|
-
return engine.resourceManager// @ts-ignore
|
|
6413
|
+
var _this = this;
|
|
6414
|
+
return this.resource.engine.resourceManager// @ts-ignore
|
|
6168
6415
|
._request(this.url, this.requestConfig).then(function(buffer) {
|
|
6169
6416
|
if (FileHeader.checkMagic(buffer)) {
|
|
6170
|
-
return decode(buffer, engine,
|
|
6171
|
-
} else {
|
|
6172
|
-
return loadImageFromBuffer(buffer).then(function(img) {
|
|
6173
|
-
texture.setImageSource(img);
|
|
6174
|
-
texture.generateMipmaps();
|
|
6175
|
-
return texture;
|
|
6176
|
-
});
|
|
6417
|
+
return decode(buffer, _this.resource.engine, _this.resource);
|
|
6177
6418
|
}
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
*/ var HDRDecoder = /*#__PURE__*/ function() {
|
|
6186
|
-
function HDRDecoder() {}
|
|
6187
|
-
HDRDecoder.parseHeader = function parseHeader(uint8array) {
|
|
6188
|
-
var line = this._readStringLine(uint8array, 0);
|
|
6189
|
-
if (line[0] !== "#" || line[1] !== "?") {
|
|
6190
|
-
throw "HDRDecoder: invalid file header";
|
|
6191
|
-
}
|
|
6192
|
-
var endOfHeader = false;
|
|
6193
|
-
var findFormat = false;
|
|
6194
|
-
var lineIndex = 0;
|
|
6195
|
-
do {
|
|
6196
|
-
lineIndex += line.length + 1;
|
|
6197
|
-
line = this._readStringLine(uint8array, lineIndex);
|
|
6198
|
-
if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
|
|
6199
|
-
else if (line.length === 0) endOfHeader = true;
|
|
6200
|
-
}while (!endOfHeader);
|
|
6201
|
-
if (!findFormat) {
|
|
6202
|
-
throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
|
|
6203
|
-
}
|
|
6204
|
-
lineIndex += line.length + 1;
|
|
6205
|
-
line = this._readStringLine(uint8array, lineIndex);
|
|
6206
|
-
var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
|
|
6207
|
-
if (!match || match.length < 3) {
|
|
6208
|
-
throw "HDRDecoder: missing image size, only -Y +X layout is supported";
|
|
6209
|
-
}
|
|
6210
|
-
var width = parseInt(match[2]);
|
|
6211
|
-
var height = parseInt(match[1]);
|
|
6212
|
-
if (width < 8 || width > 0x7fff) {
|
|
6213
|
-
throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
|
|
6214
|
-
}
|
|
6215
|
-
return {
|
|
6216
|
-
height: height,
|
|
6217
|
-
width: width,
|
|
6218
|
-
dataPosition: lineIndex + line.length + 1
|
|
6219
|
-
};
|
|
6220
|
-
};
|
|
6221
|
-
HDRDecoder.decodeFaces = function decodeFaces(bufferArray, header, onFace) {
|
|
6222
|
-
var width = header.width, height = header.height, dataPosition = header.dataPosition;
|
|
6223
|
-
var cubeSize = height >> 1;
|
|
6224
|
-
var pixels = HDRDecoder._readPixels(bufferArray.subarray(dataPosition), width, height);
|
|
6225
|
-
var faces = HDRDecoder._faces;
|
|
6226
|
-
var faceBuffer = new Uint16Array(cubeSize * cubeSize * 4);
|
|
6227
|
-
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
6228
|
-
HDRDecoder._createCubemapData(cubeSize, faces[faceIndex], pixels, width, height, faceBuffer);
|
|
6229
|
-
onFace(faceIndex, faceBuffer);
|
|
6230
|
-
}
|
|
6231
|
-
};
|
|
6232
|
-
HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
|
|
6233
|
-
var baseTable = new Uint32Array(512);
|
|
6234
|
-
var shiftTable = new Uint32Array(512);
|
|
6235
|
-
for(var i = 0; i < 256; ++i){
|
|
6236
|
-
var e = i - 127;
|
|
6237
|
-
if (e < -27) {
|
|
6238
|
-
baseTable[i] = 0x0000;
|
|
6239
|
-
baseTable[i | 0x100] = 0x8000;
|
|
6240
|
-
shiftTable[i] = 24;
|
|
6241
|
-
shiftTable[i | 0x100] = 24;
|
|
6242
|
-
} else if (e < -14) {
|
|
6243
|
-
baseTable[i] = 0x0400 >> -e - 14;
|
|
6244
|
-
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
6245
|
-
shiftTable[i] = -e - 1;
|
|
6246
|
-
shiftTable[i | 0x100] = -e - 1;
|
|
6247
|
-
} else if (e <= 15) {
|
|
6248
|
-
baseTable[i] = e + 15 << 10;
|
|
6249
|
-
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
6250
|
-
shiftTable[i] = 13;
|
|
6251
|
-
shiftTable[i | 0x100] = 13;
|
|
6252
|
-
} else if (e < 128) {
|
|
6253
|
-
baseTable[i] = 0x7c00;
|
|
6254
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
6255
|
-
shiftTable[i] = 24;
|
|
6256
|
-
shiftTable[i | 0x100] = 24;
|
|
6257
|
-
} else {
|
|
6258
|
-
baseTable[i] = 0x7c00;
|
|
6259
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
6260
|
-
shiftTable[i] = 13;
|
|
6261
|
-
shiftTable[i | 0x100] = 13;
|
|
6262
|
-
}
|
|
6263
|
-
}
|
|
6264
|
-
return {
|
|
6265
|
-
baseTable: baseTable,
|
|
6266
|
-
shiftTable: shiftTable
|
|
6267
|
-
};
|
|
6268
|
-
};
|
|
6269
|
-
HDRDecoder._createCubemapData = function _createCubemapData(texSize, face, pixels, inputWidth, inputHeight, facePixels) {
|
|
6270
|
-
var invSize = 1 / texSize;
|
|
6271
|
-
var rotDX1X = (face[3] - face[0]) * invSize;
|
|
6272
|
-
var rotDX1Y = (face[4] - face[1]) * invSize;
|
|
6273
|
-
var rotDX1Z = (face[5] - face[2]) * invSize;
|
|
6274
|
-
var rotDX2X = (face[9] - face[6]) * invSize;
|
|
6275
|
-
var rotDX2Y = (face[10] - face[7]) * invSize;
|
|
6276
|
-
var rotDX2Z = (face[11] - face[8]) * invSize;
|
|
6277
|
-
var floatView = HDRDecoder._floatView;
|
|
6278
|
-
var uint32View = HDRDecoder._uint32View;
|
|
6279
|
-
var _HDRDecoder__float2HalfTables = HDRDecoder._float2HalfTables, baseTable = _HDRDecoder__float2HalfTables.baseTable, shiftTable = _HDRDecoder__float2HalfTables.shiftTable;
|
|
6280
|
-
var one = HDRDecoder._one;
|
|
6281
|
-
var fy = 0;
|
|
6282
|
-
for(var y = 0; y < texSize; y++){
|
|
6283
|
-
var xv1X = face[0], xv1Y = face[1], xv1Z = face[2];
|
|
6284
|
-
var xv2X = face[6], xv2Y = face[7], xv2Z = face[8];
|
|
6285
|
-
for(var x = 0; x < texSize; x++){
|
|
6286
|
-
var dirX = xv1X + (xv2X - xv1X) * fy;
|
|
6287
|
-
var dirY = xv1Y + (xv2Y - xv1Y) * fy;
|
|
6288
|
-
var dirZ = xv1Z + (xv2Z - xv1Z) * fy;
|
|
6289
|
-
var invLen = 1 / Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
|
|
6290
|
-
dirX *= invLen;
|
|
6291
|
-
dirY *= invLen;
|
|
6292
|
-
dirZ *= invLen;
|
|
6293
|
-
var px = Math.round((Math.atan2(dirZ, dirX) / Math.PI * 0.5 + 0.5) * inputWidth);
|
|
6294
|
-
if (px < 0) px = 0;
|
|
6295
|
-
else if (px >= inputWidth) px = inputWidth - 1;
|
|
6296
|
-
var py = Math.round(Math.acos(dirY) / Math.PI * inputHeight);
|
|
6297
|
-
if (py < 0) py = 0;
|
|
6298
|
-
else if (py >= inputHeight) py = inputHeight - 1;
|
|
6299
|
-
var srcIndex = (inputHeight - py - 1) * inputWidth * 4 + px * 4;
|
|
6300
|
-
var scaleFactor = Math.pow(2, pixels[srcIndex + 3] - 128) / 255;
|
|
6301
|
-
var dstIndex = y * texSize * 4 + x * 4;
|
|
6302
|
-
for(var c = 0; c < 3; c++){
|
|
6303
|
-
// Clamp to half-float max (65504) to prevent Infinity in R16G16B16A16
|
|
6304
|
-
floatView[0] = Math.min(pixels[srcIndex + c] * scaleFactor, 65504);
|
|
6305
|
-
var f = uint32View[0];
|
|
6306
|
-
var e = f >> 23 & 0x1ff;
|
|
6307
|
-
facePixels[dstIndex + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
|
|
6308
|
-
}
|
|
6309
|
-
facePixels[dstIndex + 3] = one;
|
|
6310
|
-
xv1X += rotDX1X;
|
|
6311
|
-
xv1Y += rotDX1Y;
|
|
6312
|
-
xv1Z += rotDX1Z;
|
|
6313
|
-
xv2X += rotDX2X;
|
|
6314
|
-
xv2Y += rotDX2Y;
|
|
6315
|
-
xv2Z += rotDX2Z;
|
|
6316
|
-
}
|
|
6317
|
-
fy += invSize;
|
|
6318
|
-
}
|
|
6319
|
-
};
|
|
6320
|
-
HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
|
|
6321
|
-
var line = "";
|
|
6322
|
-
for(var i = startIndex, n = uint8array.length; i < n; i++){
|
|
6323
|
-
var character = String.fromCharCode(uint8array[i]);
|
|
6324
|
-
if (character === "\n") break;
|
|
6325
|
-
line += character;
|
|
6326
|
-
}
|
|
6327
|
-
return line;
|
|
6328
|
-
};
|
|
6329
|
-
HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
|
|
6330
|
-
var byteLength = buffer.byteLength;
|
|
6331
|
-
var dataRGBA = new Uint8Array(4 * width * height);
|
|
6332
|
-
var offset = 0;
|
|
6333
|
-
var pos = 0;
|
|
6334
|
-
var ptrEnd = 4 * width;
|
|
6335
|
-
var scanLineBuffer = new Uint8Array(ptrEnd);
|
|
6336
|
-
var numScanLines = height;
|
|
6337
|
-
while(numScanLines > 0 && pos < byteLength){
|
|
6338
|
-
var a = buffer[pos++];
|
|
6339
|
-
var b = buffer[pos++];
|
|
6340
|
-
var c = buffer[pos++];
|
|
6341
|
-
var d = buffer[pos++];
|
|
6342
|
-
if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
|
|
6343
|
-
if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
|
|
6344
|
-
var ptr = 0;
|
|
6345
|
-
while(ptr < ptrEnd && pos < byteLength){
|
|
6346
|
-
var count = buffer[pos++];
|
|
6347
|
-
var isEncodedRun = count > 128;
|
|
6348
|
-
if (isEncodedRun) count -= 128;
|
|
6349
|
-
if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
|
|
6350
|
-
if (isEncodedRun) {
|
|
6351
|
-
var byteValue = buffer[pos++];
|
|
6352
|
-
for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
|
|
6353
|
-
} else {
|
|
6354
|
-
scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
|
|
6355
|
-
ptr += count;
|
|
6356
|
-
pos += count;
|
|
6357
|
-
}
|
|
6358
|
-
}
|
|
6359
|
-
for(var i1 = 0; i1 < width; i1++, offset += 4){
|
|
6360
|
-
dataRGBA[offset] = scanLineBuffer[i1];
|
|
6361
|
-
dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
|
|
6362
|
-
dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
|
|
6363
|
-
dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
|
|
6419
|
+
var bufferView = new Uint8Array(buffer);
|
|
6420
|
+
var texture = _this.resource;
|
|
6421
|
+
if (bufferView[0] === 0x23 && bufferView[1] === 0x3f) {
|
|
6422
|
+
var pixels = HDRDecoder.decode(bufferView).pixels;
|
|
6423
|
+
texture.setPixelBuffer(pixels);
|
|
6424
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6425
|
+
return texture;
|
|
6364
6426
|
}
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
-1,
|
|
6382
|
-
-1,
|
|
6383
|
-
1,
|
|
6384
|
-
-1,
|
|
6385
|
-
1,
|
|
6386
|
-
1,
|
|
6387
|
-
1,
|
|
6388
|
-
-1,
|
|
6389
|
-
1,
|
|
6390
|
-
1,
|
|
6391
|
-
1
|
|
6392
|
-
],
|
|
6393
|
-
/* -X */ [
|
|
6394
|
-
-1,
|
|
6395
|
-
-1,
|
|
6396
|
-
1,
|
|
6397
|
-
-1,
|
|
6398
|
-
-1,
|
|
6399
|
-
-1,
|
|
6400
|
-
-1,
|
|
6401
|
-
1,
|
|
6402
|
-
1,
|
|
6403
|
-
-1,
|
|
6404
|
-
1,
|
|
6405
|
-
-1
|
|
6406
|
-
],
|
|
6407
|
-
/* +Y */ [
|
|
6408
|
-
-1,
|
|
6409
|
-
-1,
|
|
6410
|
-
1,
|
|
6411
|
-
1,
|
|
6412
|
-
-1,
|
|
6413
|
-
1,
|
|
6414
|
-
-1,
|
|
6415
|
-
-1,
|
|
6416
|
-
-1,
|
|
6417
|
-
1,
|
|
6418
|
-
-1,
|
|
6419
|
-
-1
|
|
6420
|
-
],
|
|
6421
|
-
/* -Y */ [
|
|
6422
|
-
-1,
|
|
6423
|
-
1,
|
|
6424
|
-
-1,
|
|
6425
|
-
1,
|
|
6426
|
-
1,
|
|
6427
|
-
-1,
|
|
6428
|
-
-1,
|
|
6429
|
-
1,
|
|
6430
|
-
1,
|
|
6431
|
-
1,
|
|
6432
|
-
1,
|
|
6433
|
-
1
|
|
6434
|
-
],
|
|
6435
|
-
/* +Z */ [
|
|
6436
|
-
-1,
|
|
6437
|
-
-1,
|
|
6438
|
-
-1,
|
|
6439
|
-
1,
|
|
6440
|
-
-1,
|
|
6441
|
-
-1,
|
|
6442
|
-
-1,
|
|
6443
|
-
1,
|
|
6444
|
-
-1,
|
|
6445
|
-
1,
|
|
6446
|
-
1,
|
|
6447
|
-
-1
|
|
6448
|
-
],
|
|
6449
|
-
/* -Z */ [
|
|
6450
|
-
1,
|
|
6451
|
-
-1,
|
|
6452
|
-
1,
|
|
6453
|
-
-1,
|
|
6454
|
-
-1,
|
|
6455
|
-
1,
|
|
6456
|
-
1,
|
|
6457
|
-
1,
|
|
6458
|
-
1,
|
|
6459
|
-
-1,
|
|
6460
|
-
1,
|
|
6461
|
-
1
|
|
6462
|
-
]
|
|
6463
|
-
];
|
|
6464
|
-
|
|
6465
|
-
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
6466
|
-
_inherits(TextureCubeLoader, Loader);
|
|
6467
|
-
function TextureCubeLoader() {
|
|
6468
|
-
return Loader.apply(this, arguments) || this;
|
|
6469
|
-
}
|
|
6470
|
-
var _proto = TextureCubeLoader.prototype;
|
|
6471
|
-
_proto.load = function load(item, resourceManager) {
|
|
6472
|
-
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6473
|
-
var engine = resourceManager.engine;
|
|
6474
|
-
var url = item.url;
|
|
6475
|
-
var requestConfig = _extends({}, item, {
|
|
6476
|
-
type: "arraybuffer"
|
|
6427
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6428
|
+
var blob = new Blob([
|
|
6429
|
+
buffer
|
|
6430
|
+
]);
|
|
6431
|
+
var img = new Image();
|
|
6432
|
+
img.onload = function() {
|
|
6433
|
+
URL.revokeObjectURL(img.src);
|
|
6434
|
+
texture.setImageSource(img);
|
|
6435
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6436
|
+
resolve(texture);
|
|
6437
|
+
};
|
|
6438
|
+
img.onerror = function(e) {
|
|
6439
|
+
URL.revokeObjectURL(img.src);
|
|
6440
|
+
reject(e);
|
|
6441
|
+
};
|
|
6442
|
+
img.src = URL.createObjectURL(blob);
|
|
6477
6443
|
});
|
|
6478
|
-
resourceManager// @ts-ignore
|
|
6479
|
-
._request(url, requestConfig).then(function(buffer) {
|
|
6480
|
-
if (!engineCore.SystemInfo.supportsTextureFormat(engine, engineCore.TextureFormat.R16G16B16A16)) {
|
|
6481
|
-
reject(new Error("TextureCubeLoader: HDR texture requires half float support."));
|
|
6482
|
-
return;
|
|
6483
|
-
}
|
|
6484
|
-
var _item_params;
|
|
6485
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6486
|
-
var bufferArray = new Uint8Array(buffer);
|
|
6487
|
-
var header = HDRDecoder.parseHeader(bufferArray);
|
|
6488
|
-
var texture = new engineCore.TextureCube(engine, header.height >> 1, engineCore.TextureFormat.R16G16B16A16, mipmap, false);
|
|
6489
|
-
HDRDecoder.decodeFaces(bufferArray, header, function(faceIndex, data) {
|
|
6490
|
-
texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, data, 0);
|
|
6491
|
-
});
|
|
6492
|
-
texture.generateMipmaps();
|
|
6493
|
-
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6494
|
-
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6495
|
-
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6496
|
-
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6497
|
-
resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
|
|
6498
|
-
resolve(texture);
|
|
6499
|
-
}).catch(reject);
|
|
6500
|
-
});
|
|
6501
|
-
};
|
|
6502
|
-
return TextureCubeLoader;
|
|
6503
|
-
}(engineCore.Loader);
|
|
6504
|
-
TextureCubeLoader = __decorate([
|
|
6505
|
-
engineCore.resourceLoader(engineCore.AssetType.TextureCube, [
|
|
6506
|
-
"texCube",
|
|
6507
|
-
"hdr"
|
|
6508
|
-
])
|
|
6509
|
-
], TextureCubeLoader);
|
|
6510
|
-
var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6511
|
-
_inherits(HDRContentRestorer, ContentRestorer);
|
|
6512
|
-
function HDRContentRestorer(resource, url, requestConfig) {
|
|
6513
|
-
var _this;
|
|
6514
|
-
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6515
|
-
return _this;
|
|
6516
|
-
}
|
|
6517
|
-
var _proto = HDRContentRestorer.prototype;
|
|
6518
|
-
_proto.restoreContent = function restoreContent() {
|
|
6519
|
-
var _this = this;
|
|
6520
|
-
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6521
|
-
var resource = _this.resource;
|
|
6522
|
-
resource.engine.resourceManager// @ts-ignore
|
|
6523
|
-
._request(_this.url, _this.requestConfig).then(function(buffer) {
|
|
6524
|
-
var bufferArray = new Uint8Array(buffer);
|
|
6525
|
-
HDRDecoder.decodeFaces(bufferArray, HDRDecoder.parseHeader(bufferArray), function(faceIndex, data) {
|
|
6526
|
-
resource.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + faceIndex, data, 0);
|
|
6527
|
-
});
|
|
6528
|
-
resource.generateMipmaps();
|
|
6529
|
-
resolve(resource);
|
|
6530
|
-
}).catch(reject);
|
|
6531
6444
|
});
|
|
6532
6445
|
};
|
|
6533
|
-
return
|
|
6446
|
+
return TextureContentRestorer;
|
|
6534
6447
|
}(engineCore.ContentRestorer);
|
|
6535
6448
|
|
|
6536
6449
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|