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