@galacean/engine-loader 0.0.0-experimental-2.0-game.2 → 0.0.0-experimental-2.0-game.3
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 +464 -377
- package/dist/main.js.map +1 -1
- package/dist/module.js +464 -377
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/HDRDecoder.d.ts +8 -27
- package/types/{TextureLoader.d.ts → Texture2DLoader.d.ts} +4 -4
- package/types/index.d.ts +3 -2
- package/types/resource-deserialize/index.d.ts +1 -2
- package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +9 -0
- package/types/resource-deserialize/resources/textureCube/TextureCubeDecoder.d.ts +0 -1
- /package/types/{resource-deserialize/resources/texture2D/Texture2DDecoder.d.ts → TextureCubeLoader.d.ts} +0 -0
package/dist/main.js
CHANGED
|
@@ -956,190 +956,11 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
956
956
|
return ReflectionParser;
|
|
957
957
|
}();
|
|
958
958
|
|
|
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() {
|
|
959
|
+
exports.Texture2DDecoder = /*#__PURE__*/ function() {
|
|
1139
960
|
function Texture2DDecoder() {}
|
|
1140
961
|
Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1141
962
|
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
1142
|
-
bufferReader.nextStr();
|
|
963
|
+
var url = bufferReader.nextStr();
|
|
1143
964
|
var mipmap = !!bufferReader.nextUint8();
|
|
1144
965
|
var filterMode = bufferReader.nextUint8();
|
|
1145
966
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -1148,34 +969,58 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1148
969
|
var format = bufferReader.nextUint8();
|
|
1149
970
|
var width = bufferReader.nextUint16();
|
|
1150
971
|
var height = bufferReader.nextUint16();
|
|
972
|
+
var isPixelBuffer = bufferReader.nextUint8();
|
|
1151
973
|
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
1152
|
-
var
|
|
1153
|
-
var
|
|
1154
|
-
var
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
974
|
+
var mipCount = bufferReader.nextUint8();
|
|
975
|
+
var imagesData = bufferReader.nextImagesData(mipCount);
|
|
976
|
+
var texture2D = restoredTexture || new engineCore.Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
977
|
+
texture2D.filterMode = filterMode;
|
|
978
|
+
texture2D.anisoLevel = anisoLevel;
|
|
979
|
+
texture2D.wrapModeU = wrapModeU;
|
|
980
|
+
texture2D.wrapModeV = wrapModeV;
|
|
981
|
+
if (isPixelBuffer) {
|
|
982
|
+
var pixelBuffer = imagesData[0];
|
|
983
|
+
texture2D.setPixelBuffer(pixelBuffer);
|
|
984
|
+
if (mipmap) {
|
|
985
|
+
texture2D.generateMipmaps();
|
|
986
|
+
for(var i = 1; i < mipCount; i++){
|
|
987
|
+
var pixelBuffer1 = imagesData[i];
|
|
988
|
+
texture2D.setPixelBuffer(pixelBuffer1, i);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
// @ts-ignore
|
|
992
|
+
engine.resourceManager._objectPool[url] = texture2D;
|
|
993
|
+
resolve(texture2D);
|
|
1165
994
|
} else {
|
|
1166
|
-
var blob = new Blob([
|
|
1167
|
-
|
|
995
|
+
var blob = new window.Blob([
|
|
996
|
+
imagesData[0]
|
|
1168
997
|
]);
|
|
1169
998
|
var img = new Image();
|
|
1170
999
|
img.onload = function() {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1000
|
+
texture2D.setImageSource(img);
|
|
1001
|
+
var completedCount = 0;
|
|
1002
|
+
var onComplete = function() {
|
|
1003
|
+
completedCount++;
|
|
1004
|
+
if (completedCount >= mipCount) {
|
|
1005
|
+
resolve(texture2D);
|
|
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
|
+
}
|
|
1179
1024
|
};
|
|
1180
1025
|
img.src = URL.createObjectURL(blob);
|
|
1181
1026
|
}
|
|
@@ -1183,72 +1028,9 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1183
1028
|
};
|
|
1184
1029
|
return Texture2DDecoder;
|
|
1185
1030
|
}();
|
|
1186
|
-
Texture2DDecoder = __decorate([
|
|
1031
|
+
exports.Texture2DDecoder = __decorate([
|
|
1187
1032
|
decoder("Texture2D")
|
|
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);
|
|
1033
|
+
], exports.Texture2DDecoder);
|
|
1252
1034
|
|
|
1253
1035
|
function _instanceof(left, right) {
|
|
1254
1036
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -3856,13 +3638,11 @@ function registerGLTFParser(pipeline) {
|
|
|
3856
3638
|
});
|
|
3857
3639
|
var img = new Image();
|
|
3858
3640
|
img.onerror = function() {
|
|
3859
|
-
URL.revokeObjectURL(img.src);
|
|
3860
3641
|
reject(new Error("Failed to load image buffer"));
|
|
3861
3642
|
};
|
|
3862
3643
|
img.onload = function() {
|
|
3863
3644
|
// Call requestAnimationFrame to avoid iOS's bug.
|
|
3864
3645
|
requestAnimationFrame(function() {
|
|
3865
|
-
URL.revokeObjectURL(img.src);
|
|
3866
3646
|
resolve(img);
|
|
3867
3647
|
img.onload = null;
|
|
3868
3648
|
img.onerror = null;
|
|
@@ -5327,7 +5107,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5327
5107
|
if (uri) {
|
|
5328
5108
|
var extIndex = uri.lastIndexOf(".");
|
|
5329
5109
|
var ext = uri.substring(extIndex + 1);
|
|
5330
|
-
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.
|
|
5110
|
+
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
|
|
5331
5111
|
texture = engine.resourceManager.load({
|
|
5332
5112
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
5333
5113
|
type: type,
|
|
@@ -6203,7 +5983,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6203
5983
|
var _atlasItem_type;
|
|
6204
5984
|
chainPromises.push(resourceManager.load({
|
|
6205
5985
|
url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
6206
|
-
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.
|
|
5986
|
+
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.Texture2D,
|
|
6207
5987
|
params: {
|
|
6208
5988
|
format: format,
|
|
6209
5989
|
mipmap: mipmap
|
|
@@ -6341,12 +6121,26 @@ TextLoader = __decorate([
|
|
|
6341
6121
|
])
|
|
6342
6122
|
], TextLoader);
|
|
6343
6123
|
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6124
|
+
function loadImageFromBuffer(buffer) {
|
|
6125
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6126
|
+
var blob = new Blob([
|
|
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() {
|
|
6347
6141
|
return Loader.apply(this, arguments) || this;
|
|
6348
6142
|
}
|
|
6349
|
-
var _proto =
|
|
6143
|
+
var _proto = Texture2DLoader.prototype;
|
|
6350
6144
|
_proto.load = function load(item, resourceManager) {
|
|
6351
6145
|
var _this = this;
|
|
6352
6146
|
var url = item.url;
|
|
@@ -6356,136 +6150,429 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6356
6150
|
return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
|
|
6357
6151
|
resourceManager// @ts-ignore
|
|
6358
6152
|
._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
|
|
6359
|
-
|
|
6360
|
-
resourceManager.
|
|
6361
|
-
|
|
6362
|
-
|
|
6153
|
+
if (FileHeader.checkMagic(buffer)) {
|
|
6154
|
+
decode(buffer, resourceManager.engine).then(function(texture) {
|
|
6155
|
+
resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
|
|
6156
|
+
resolve(texture);
|
|
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
|
+
}
|
|
6363
6165
|
}).catch(reject);
|
|
6364
6166
|
});
|
|
6365
6167
|
};
|
|
6366
|
-
_proto.
|
|
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) {
|
|
6168
|
+
_proto._createTexture = function _createTexture(img, item, resourceManager) {
|
|
6423
6169
|
var _item_params;
|
|
6424
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6170
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
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);
|
|
6425
6175
|
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6426
6176
|
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6427
6177
|
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6428
6178
|
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6179
|
+
texture.setImageSource(img);
|
|
6180
|
+
generateMipmap && texture.generateMipmaps();
|
|
6429
6181
|
var url = item.url;
|
|
6430
6182
|
if (url.indexOf("data:") !== 0) {
|
|
6431
6183
|
texture.name = url.substring(url.lastIndexOf("/") + 1);
|
|
6432
6184
|
}
|
|
6185
|
+
return texture;
|
|
6433
6186
|
};
|
|
6434
|
-
return
|
|
6187
|
+
return Texture2DLoader;
|
|
6435
6188
|
}(engineCore.Loader);
|
|
6436
|
-
|
|
6437
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
6438
|
-
"tex",
|
|
6189
|
+
Texture2DLoader = __decorate([
|
|
6190
|
+
engineCore.resourceLoader(engineCore.AssetType.Texture2D, [
|
|
6439
6191
|
"png",
|
|
6440
6192
|
"jpg",
|
|
6441
6193
|
"webp",
|
|
6442
6194
|
"jpeg",
|
|
6443
|
-
"
|
|
6195
|
+
"tex"
|
|
6444
6196
|
])
|
|
6445
|
-
],
|
|
6446
|
-
var
|
|
6447
|
-
_inherits(
|
|
6448
|
-
function
|
|
6197
|
+
], Texture2DLoader);
|
|
6198
|
+
var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6199
|
+
_inherits(Texture2DContentRestorer, ContentRestorer);
|
|
6200
|
+
function Texture2DContentRestorer(resource, url, requestConfig) {
|
|
6449
6201
|
var _this;
|
|
6450
6202
|
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6451
6203
|
return _this;
|
|
6452
6204
|
}
|
|
6453
|
-
var _proto =
|
|
6205
|
+
var _proto = Texture2DContentRestorer.prototype;
|
|
6454
6206
|
_proto.restoreContent = function restoreContent() {
|
|
6455
|
-
var
|
|
6456
|
-
|
|
6207
|
+
var texture = this.resource;
|
|
6208
|
+
var engine = texture.engine;
|
|
6209
|
+
return engine.resourceManager// @ts-ignore
|
|
6457
6210
|
._request(this.url, this.requestConfig).then(function(buffer) {
|
|
6458
6211
|
if (FileHeader.checkMagic(buffer)) {
|
|
6459
|
-
return decode(buffer,
|
|
6460
|
-
}
|
|
6461
|
-
|
|
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;
|
|
6468
|
-
}
|
|
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);
|
|
6212
|
+
return decode(buffer, engine, texture);
|
|
6213
|
+
} else {
|
|
6214
|
+
return loadImageFromBuffer(buffer).then(function(img) {
|
|
6476
6215
|
texture.setImageSource(img);
|
|
6477
|
-
texture.
|
|
6478
|
-
|
|
6479
|
-
};
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6216
|
+
texture.generateMipmaps();
|
|
6217
|
+
return texture;
|
|
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];
|
|
6406
|
+
}
|
|
6407
|
+
numScanLines--;
|
|
6408
|
+
}
|
|
6409
|
+
return dataRGBA;
|
|
6410
|
+
};
|
|
6411
|
+
return HDRDecoder;
|
|
6412
|
+
}();
|
|
6413
|
+
// Float32 to Float16 lookup tables (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf)
|
|
6414
|
+
HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
6415
|
+
HDRDecoder._floatView = new Float32Array(1);
|
|
6416
|
+
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
6417
|
+
HDRDecoder._one = 0x3c00 // Half float for 1.0
|
|
6418
|
+
;
|
|
6419
|
+
// prettier-ignore
|
|
6420
|
+
HDRDecoder._faces = [
|
|
6421
|
+
/* +X */ [
|
|
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
|
+
/* -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"
|
|
6485
6519
|
});
|
|
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);
|
|
6486
6573
|
});
|
|
6487
6574
|
};
|
|
6488
|
-
return
|
|
6575
|
+
return HDRContentRestorer;
|
|
6489
6576
|
}(engineCore.ContentRestorer);
|
|
6490
6577
|
|
|
6491
6578
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|