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