@galacean/engine-loader 2.0.0-alpha.24 → 2.0.0-alpha.26
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 +391 -475
- package/dist/main.js.map +1 -1
- package/dist/module.js +391 -475
- 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;
|
|
@@ -4763,16 +4983,11 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4763
4983
|
var isDefaultScene = scene === index;
|
|
4764
4984
|
var sceneNodes = sceneInfo.nodes || [];
|
|
4765
4985
|
var sceneRoot;
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
sceneRoot._markAsTemplate(glTFResource);
|
|
4772
|
-
for(var i = 0; i < sceneNodes.length; i++){
|
|
4773
|
-
var childEntity = context.get(GLTFParserType.Entity, sceneNodes[i]);
|
|
4774
|
-
sceneRoot.addChild(childEntity);
|
|
4775
|
-
}
|
|
4986
|
+
sceneRoot = new engineCore.Entity(engine, "GLTF_ROOT");
|
|
4987
|
+
// @ts-ignore
|
|
4988
|
+
sceneRoot._markAsTemplate(glTFResource);
|
|
4989
|
+
for(var i = 0; i < sceneNodes.length; i++){
|
|
4990
|
+
sceneRoot.addChild(context.get(GLTFParserType.Entity, sceneNodes[i]));
|
|
4776
4991
|
}
|
|
4777
4992
|
if (isDefaultScene) {
|
|
4778
4993
|
glTFResource._defaultSceneRoot = sceneRoot;
|
|
@@ -5065,7 +5280,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5065
5280
|
if (uri) {
|
|
5066
5281
|
var extIndex = uri.lastIndexOf(".");
|
|
5067
5282
|
var ext = uri.substring(extIndex + 1);
|
|
5068
|
-
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.
|
|
5283
|
+
var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture;
|
|
5069
5284
|
texture = engine.resourceManager.load({
|
|
5070
5285
|
url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
|
|
5071
5286
|
type: type,
|
|
@@ -5941,7 +6156,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5941
6156
|
var _atlasItem_type;
|
|
5942
6157
|
chainPromises.push(resourceManager.load({
|
|
5943
6158
|
url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
|
|
5944
|
-
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.
|
|
6159
|
+
type: (_atlasItem_type = atlasItem.type) != null ? _atlasItem_type : engineCore.AssetType.Texture,
|
|
5945
6160
|
params: {
|
|
5946
6161
|
format: format,
|
|
5947
6162
|
mipmap: mipmap
|
|
@@ -6079,26 +6294,12 @@ TextLoader = __decorate([
|
|
|
6079
6294
|
])
|
|
6080
6295
|
], TextLoader);
|
|
6081
6296
|
|
|
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() {
|
|
6297
|
+
var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
6298
|
+
_inherits(TextureLoader, Loader);
|
|
6299
|
+
function TextureLoader() {
|
|
6099
6300
|
return Loader.apply(this, arguments) || this;
|
|
6100
6301
|
}
|
|
6101
|
-
var _proto =
|
|
6302
|
+
var _proto = TextureLoader.prototype;
|
|
6102
6303
|
_proto.load = function load(item, resourceManager) {
|
|
6103
6304
|
var _this = this;
|
|
6104
6305
|
var url = item.url;
|
|
@@ -6108,429 +6309,136 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6108
6309
|
return new engineCore.AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
|
|
6109
6310
|
resourceManager// @ts-ignore
|
|
6110
6311
|
._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
|
-
}
|
|
6312
|
+
_this._decode(buffer, item, resourceManager).then(function(texture) {
|
|
6313
|
+
resourceManager.addContentRestorer(new TextureContentRestorer(texture, url, requestConfig));
|
|
6314
|
+
resolve(texture);
|
|
6315
|
+
}, reject);
|
|
6123
6316
|
}).catch(reject);
|
|
6124
6317
|
});
|
|
6125
6318
|
};
|
|
6126
|
-
_proto.
|
|
6319
|
+
_proto._decode = function _decode(buffer, item, resourceManager) {
|
|
6320
|
+
if (FileHeader.checkMagic(buffer)) {
|
|
6321
|
+
return decode(buffer, resourceManager.engine);
|
|
6322
|
+
}
|
|
6323
|
+
var bufferView = new Uint8Array(buffer);
|
|
6324
|
+
var isHDR = bufferView[0] === 0x23 && bufferView[1] === 0x3f;
|
|
6325
|
+
if (isHDR) {
|
|
6326
|
+
return this._decodeHDR(bufferView, item, resourceManager);
|
|
6327
|
+
}
|
|
6328
|
+
return this._decodeImage(buffer, item, resourceManager);
|
|
6329
|
+
};
|
|
6330
|
+
_proto._decodeHDR = function _decodeHDR(buffer, item, resourceManager) {
|
|
6331
|
+
var _this = this;
|
|
6332
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6333
|
+
var engine = resourceManager.engine;
|
|
6334
|
+
if (!engineCore.SystemInfo.supportsTextureFormat(engine, engineCore.TextureFormat.R16G16B16A16)) {
|
|
6335
|
+
reject(new Error("TextureLoader: HDR texture requires half float support."));
|
|
6336
|
+
return;
|
|
6337
|
+
}
|
|
6338
|
+
var _HDRDecoder_decode = HDRDecoder.decode(buffer), width = _HDRDecoder_decode.width, height = _HDRDecoder_decode.height, pixels = _HDRDecoder_decode.pixels;
|
|
6339
|
+
var _item_params;
|
|
6340
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
|
|
6341
|
+
var texture = new engineCore.Texture2D(engine, width, height, engineCore.TextureFormat.R16G16B16A16, mipmap, false);
|
|
6342
|
+
texture.setPixelBuffer(pixels);
|
|
6343
|
+
mipmap && texture.generateMipmaps();
|
|
6344
|
+
_this._applyParams(texture, item);
|
|
6345
|
+
resolve(texture);
|
|
6346
|
+
});
|
|
6347
|
+
};
|
|
6348
|
+
_proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
|
|
6349
|
+
var _this = this;
|
|
6350
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6351
|
+
var blob = new Blob([
|
|
6352
|
+
buffer
|
|
6353
|
+
]);
|
|
6354
|
+
var img = new Image();
|
|
6355
|
+
img.onload = function() {
|
|
6356
|
+
URL.revokeObjectURL(img.src);
|
|
6357
|
+
var _item_params;
|
|
6358
|
+
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;
|
|
6359
|
+
var engine = resourceManager.engine;
|
|
6360
|
+
var width = img.width, height = img.height;
|
|
6361
|
+
var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
6362
|
+
var texture = new engineCore.Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6363
|
+
texture.setImageSource(img);
|
|
6364
|
+
generateMipmap && texture.generateMipmaps();
|
|
6365
|
+
_this._applyParams(texture, item);
|
|
6366
|
+
resolve(texture);
|
|
6367
|
+
};
|
|
6368
|
+
img.onerror = function(e) {
|
|
6369
|
+
URL.revokeObjectURL(img.src);
|
|
6370
|
+
reject(e);
|
|
6371
|
+
};
|
|
6372
|
+
img.src = URL.createObjectURL(blob);
|
|
6373
|
+
});
|
|
6374
|
+
};
|
|
6375
|
+
_proto._applyParams = function _applyParams(texture, item) {
|
|
6127
6376
|
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);
|
|
6377
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
|
|
6133
6378
|
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6134
6379
|
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6135
6380
|
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6136
6381
|
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6137
|
-
texture.setImageSource(img);
|
|
6138
|
-
generateMipmap && texture.generateMipmaps();
|
|
6139
6382
|
var url = item.url;
|
|
6140
6383
|
if (url.indexOf("data:") !== 0) {
|
|
6141
6384
|
texture.name = url.substring(url.lastIndexOf("/") + 1);
|
|
6142
6385
|
}
|
|
6143
|
-
return texture;
|
|
6144
6386
|
};
|
|
6145
|
-
return
|
|
6387
|
+
return TextureLoader;
|
|
6146
6388
|
}(engineCore.Loader);
|
|
6147
|
-
|
|
6148
|
-
engineCore.resourceLoader(engineCore.AssetType.
|
|
6389
|
+
TextureLoader = __decorate([
|
|
6390
|
+
engineCore.resourceLoader(engineCore.AssetType.Texture, [
|
|
6391
|
+
"tex",
|
|
6149
6392
|
"png",
|
|
6150
6393
|
"jpg",
|
|
6151
6394
|
"webp",
|
|
6152
6395
|
"jpeg",
|
|
6153
|
-
"
|
|
6396
|
+
"hdr"
|
|
6154
6397
|
])
|
|
6155
|
-
],
|
|
6156
|
-
var
|
|
6157
|
-
_inherits(
|
|
6158
|
-
function
|
|
6398
|
+
], TextureLoader);
|
|
6399
|
+
var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
6400
|
+
_inherits(TextureContentRestorer, ContentRestorer);
|
|
6401
|
+
function TextureContentRestorer(resource, url, requestConfig) {
|
|
6159
6402
|
var _this;
|
|
6160
6403
|
_this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
|
|
6161
6404
|
return _this;
|
|
6162
6405
|
}
|
|
6163
|
-
var _proto =
|
|
6406
|
+
var _proto = TextureContentRestorer.prototype;
|
|
6164
6407
|
_proto.restoreContent = function restoreContent() {
|
|
6165
|
-
var
|
|
6166
|
-
|
|
6167
|
-
return engine.resourceManager// @ts-ignore
|
|
6408
|
+
var _this = this;
|
|
6409
|
+
return this.resource.engine.resourceManager// @ts-ignore
|
|
6168
6410
|
._request(this.url, this.requestConfig).then(function(buffer) {
|
|
6169
6411
|
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
|
-
});
|
|
6412
|
+
return decode(buffer, _this.resource.engine, _this.resource);
|
|
6177
6413
|
}
|
|
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];
|
|
6414
|
+
var bufferView = new Uint8Array(buffer);
|
|
6415
|
+
var texture = _this.resource;
|
|
6416
|
+
if (bufferView[0] === 0x23 && bufferView[1] === 0x3f) {
|
|
6417
|
+
var pixels = HDRDecoder.decode(bufferView).pixels;
|
|
6418
|
+
texture.setPixelBuffer(pixels);
|
|
6419
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6420
|
+
return texture;
|
|
6364
6421
|
}
|
|
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"
|
|
6422
|
+
return new engineCore.AssetPromise(function(resolve, reject) {
|
|
6423
|
+
var blob = new Blob([
|
|
6424
|
+
buffer
|
|
6425
|
+
]);
|
|
6426
|
+
var img = new Image();
|
|
6427
|
+
img.onload = function() {
|
|
6428
|
+
URL.revokeObjectURL(img.src);
|
|
6429
|
+
texture.setImageSource(img);
|
|
6430
|
+
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6431
|
+
resolve(texture);
|
|
6432
|
+
};
|
|
6433
|
+
img.onerror = function(e) {
|
|
6434
|
+
URL.revokeObjectURL(img.src);
|
|
6435
|
+
reject(e);
|
|
6436
|
+
};
|
|
6437
|
+
img.src = URL.createObjectURL(blob);
|
|
6477
6438
|
});
|
|
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
6439
|
});
|
|
6501
6440
|
};
|
|
6502
|
-
return
|
|
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
|
-
});
|
|
6532
|
-
};
|
|
6533
|
-
return HDRContentRestorer;
|
|
6441
|
+
return TextureContentRestorer;
|
|
6534
6442
|
}(engineCore.ContentRestorer);
|
|
6535
6443
|
|
|
6536
6444
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
@@ -6629,6 +6537,15 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6629
6537
|
_proto.load = function load(item, resourceManager) {
|
|
6630
6538
|
var _this = this;
|
|
6631
6539
|
var url = item.url;
|
|
6540
|
+
if (url.endsWith(".gsp")) {
|
|
6541
|
+
// @ts-ignore
|
|
6542
|
+
return resourceManager._request(url, _extends({}, item, {
|
|
6543
|
+
type: "json"
|
|
6544
|
+
})).then(function(data) {
|
|
6545
|
+
// @ts-ignore - _createFromPrecompiled is @internal
|
|
6546
|
+
return engineCore.Shader._createFromPrecompiled(data);
|
|
6547
|
+
});
|
|
6548
|
+
}
|
|
6632
6549
|
// @ts-ignore
|
|
6633
6550
|
return resourceManager._request(url, _extends({}, item, {
|
|
6634
6551
|
type: "text"
|
|
@@ -6652,8 +6569,7 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6652
6569
|
ShaderLoader._builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/;
|
|
6653
6570
|
ShaderLoader = __decorate([
|
|
6654
6571
|
engineCore.resourceLoader(engineCore.AssetType.Shader, [
|
|
6655
|
-
"
|
|
6656
|
-
"gsl"
|
|
6572
|
+
"shader"
|
|
6657
6573
|
])
|
|
6658
6574
|
], ShaderLoader);
|
|
6659
6575
|
|