@galacean/engine-loader 1.4.15 → 1.5.0-alpha.0

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 CHANGED
@@ -437,9 +437,10 @@ exports.Texture2DDecoder = /*#__PURE__*/ function() {
437
437
  var width = bufferReader.nextUint16();
438
438
  var height = bufferReader.nextUint16();
439
439
  var isPixelBuffer = bufferReader.nextUint8();
440
+ var isSRGBColorSpace = !!bufferReader.nextUint8();
440
441
  var mipCount = bufferReader.nextUint8();
441
442
  var imagesData = bufferReader.nextImagesData(mipCount);
442
- var texture2D = new engineCore.Texture2D(engine, width, height, format, mipmap);
443
+ var texture2D = new engineCore.Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
443
444
  texture2D.filterMode = filterMode;
444
445
  texture2D.anisoLevel = anisoLevel;
445
446
  texture2D.wrapModeU = wrapModeU;
@@ -1690,7 +1691,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
1690
1691
  var _this;
1691
1692
  var shByteLength = 27 * 4;
1692
1693
  var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
1693
- texture || (texture = new engineCore.TextureCube(engine, size));
1694
+ texture || (texture = new engineCore.TextureCube(engine, size, undefined, undefined, false));
1694
1695
  texture.filterMode = engineCore.TextureFilterMode.Trilinear;
1695
1696
  var mipmapCount = texture.mipmapCount;
1696
1697
  var offset = shByteLength + 2;
@@ -2421,8 +2422,8 @@ var GLTFParserType = /*#__PURE__*/ function(GLTFParserType) {
2421
2422
  }({});
2422
2423
  var _obj$3;
2423
2424
  var glTFSchemaMap = (_obj$3 = {}, _obj$3[2] = "scenes", _obj$3[3] = "buffers", _obj$3[5] = "textures", _obj$3[6] = "materials", _obj$3[7] = "meshes", _obj$3[8] = "nodes", _obj$3[9] = "skins", _obj$3[10] = "animations", _obj$3[4] = "bufferViews", _obj$3);
2424
- var _obj1;
2425
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1[11] = "animatorController", _obj1);
2425
+ var _obj1$1;
2426
+ var glTFResourceMap = (_obj1$1 = {}, _obj1$1[2] = "_sceneRoots", _obj1$1[5] = "textures", _obj1$1[6] = "materials", _obj1$1[7] = "meshes", _obj1$1[8] = "entities", _obj1$1[9] = "skins", _obj1$1[10] = "animations", _obj1$1[11] = "animatorController", _obj1$1);
2426
2427
  function registerGLTFParser(pipeline) {
2427
2428
  return function(Parser) {
2428
2429
  var parser = new Parser();
@@ -2817,6 +2818,11 @@ function registerGLTFParser(pipeline) {
2817
2818
  return GLTFUtils;
2818
2819
  }();
2819
2820
 
2821
+ var DFDTransferFunction = /*#__PURE__*/ function(DFDTransferFunction) {
2822
+ DFDTransferFunction[DFDTransferFunction["linear"] = 1] = "linear";
2823
+ DFDTransferFunction[DFDTransferFunction["sRGB"] = 2] = "sRGB";
2824
+ return DFDTransferFunction;
2825
+ }({});
2820
2826
  var SupercompressionScheme = /*#__PURE__*/ function(SupercompressionScheme) {
2821
2827
  SupercompressionScheme[SupercompressionScheme["None"] = 0] = "None";
2822
2828
  SupercompressionScheme[SupercompressionScheme["BasisLZ"] = 1] = "BasisLZ";
@@ -3611,8 +3617,8 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3611
3617
  type: "arraybuffer"
3612
3618
  }).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
3613
3619
  return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
3614
- var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
3615
- return KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
3620
+ var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
3621
+ return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
3616
3622
  });
3617
3623
  }).then(resolve).catch(reject);
3618
3624
  });
@@ -3646,6 +3652,7 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3646
3652
  }
3647
3653
  return transcodeResultPromise.then(function(result) {
3648
3654
  return {
3655
+ ktx2Container: ktx2Container,
3649
3656
  engine: engine,
3650
3657
  result: result,
3651
3658
  targetFormat: targetFormat,
@@ -3653,7 +3660,7 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3653
3660
  };
3654
3661
  });
3655
3662
  };
3656
- /** @internal */ KTX2Loader._createTextureByBuffer = function _createTextureByBuffer(engine, transcodeResult, targetFormat, params) {
3663
+ /** @internal */ KTX2Loader._createTextureByBuffer = function _createTextureByBuffer(engine, isSRGB, transcodeResult, targetFormat, params) {
3657
3664
  var width = transcodeResult.width, height = transcodeResult.height, faces = transcodeResult.faces;
3658
3665
  var faceCount = faces.length;
3659
3666
  var mipmaps = faces[0];
@@ -3661,13 +3668,13 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3661
3668
  var engineFormat = this._getEngineTextureFormat(targetFormat, transcodeResult);
3662
3669
  var texture;
3663
3670
  if (faceCount !== 6) {
3664
- texture = new engineCore.Texture2D(engine, width, height, engineFormat, mipmap);
3671
+ texture = new engineCore.Texture2D(engine, width, height, engineFormat, mipmap, isSRGB);
3665
3672
  for(var mipLevel = 0; mipLevel < mipmaps.length; mipLevel++){
3666
3673
  var data = mipmaps[mipLevel].data;
3667
3674
  texture.setPixelBuffer(data, mipLevel);
3668
3675
  }
3669
3676
  } else {
3670
- texture = new engineCore.TextureCube(engine, height, engineFormat, mipmap);
3677
+ texture = new engineCore.TextureCube(engine, height, engineFormat, mipmap, isSRGB);
3671
3678
  for(var i = 0; i < faces.length; i++){
3672
3679
  var faceData = faces[i];
3673
3680
  for(var mipLevel1 = 0; mipLevel1 < mipmaps.length; mipLevel1++){
@@ -3685,8 +3692,9 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3685
3692
  };
3686
3693
  KTX2Loader._decideTargetFormat = function _decideTargetFormat(engine, ktx2Container, priorityFormats) {
3687
3694
  var renderer = engine._hardwareRenderer;
3688
- var targetFormat = this._detectSupportedFormat(renderer, priorityFormats);
3689
- if (targetFormat === KTX2TargetFormat.PVRTC && (!engineMath.MathUtil.isPowerOf2(ktx2Container.pixelWidth) || !engineMath.MathUtil.isPowerOf2(ktx2Container.pixelHeight) || ktx2Container.pixelWidth !== ktx2Container.pixelHeight)) {
3695
+ var isSRGB = ktx2Container.isSRGB, pixelWidth = ktx2Container.pixelWidth, pixelHeight = ktx2Container.pixelHeight;
3696
+ var targetFormat = this._detectSupportedFormat(renderer, priorityFormats, isSRGB);
3697
+ if (targetFormat === KTX2TargetFormat.PVRTC && (!engineMath.MathUtil.isPowerOf2(pixelWidth) || !engineMath.MathUtil.isPowerOf2(pixelHeight) || pixelWidth !== pixelHeight)) {
3690
3698
  engineCore.Logger.warn("PVRTC image need power of 2 and width===height, downgrade to RGBA8");
3691
3699
  return KTX2TargetFormat.R8G8B8A8;
3692
3700
  }
@@ -3696,10 +3704,11 @@ exports.KTX2Loader = /*#__PURE__*/ function(Loader) {
3696
3704
  }
3697
3705
  return targetFormat;
3698
3706
  };
3699
- KTX2Loader._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats) {
3707
+ KTX2Loader._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats, isSRGB) {
3700
3708
  for(var i = 0; i < priorityFormats.length; i++){
3709
+ var _this__capabilityMap_format;
3701
3710
  var format = priorityFormats[i];
3702
- var capabilities = this._supportedMap[format];
3711
+ var capabilities = (_this__capabilityMap_format = this._capabilityMap[format]) == null ? void 0 : _this__capabilityMap_format[isSRGB ? DFDTransferFunction.sRGB : DFDTransferFunction.linear];
3703
3712
  if (capabilities) {
3704
3713
  for(var j = 0; j < capabilities.length; j++){
3705
3714
  if (renderer.canIUse(capabilities[j])) {
@@ -3765,19 +3774,31 @@ exports.KTX2Loader._priorityFormats = {
3765
3774
  KTX2TargetFormat.PVRTC
3766
3775
  ]
3767
3776
  };
3768
- var _obj$1;
3769
- exports.KTX2Loader._supportedMap = (_obj$1 = {}, _obj$1[KTX2TargetFormat.ASTC] = [
3770
- engineCore.GLCapabilityType.astc
3771
- ], _obj$1[KTX2TargetFormat.ETC] = [
3772
- engineCore.GLCapabilityType.etc
3773
- ], _obj$1[KTX2TargetFormat.BC7] = [
3777
+ var _obj$1, _obj1, _obj2, _obj3, _obj4, _obj5;
3778
+ exports.KTX2Loader._capabilityMap = (_obj5 = {}, _obj5[KTX2TargetFormat.ASTC] = (_obj$1 = {}, _obj$1[DFDTransferFunction.linear] = [
3779
+ engineCore.GLCapabilityType.astc,
3780
+ engineCore.GLCapabilityType.astc_webkit
3781
+ ], _obj$1[DFDTransferFunction.sRGB] = [
3782
+ engineCore.GLCapabilityType.astc,
3783
+ engineCore.GLCapabilityType.astc_webkit
3784
+ ], _obj$1), _obj5[KTX2TargetFormat.ETC] = (_obj1 = {}, _obj1[DFDTransferFunction.linear] = [
3785
+ engineCore.GLCapabilityType.etc,
3786
+ engineCore.GLCapabilityType.etc_webkit
3787
+ ], _obj1[DFDTransferFunction.sRGB] = [
3788
+ engineCore.GLCapabilityType.etc,
3789
+ engineCore.GLCapabilityType.etc_webkit
3790
+ ], _obj1), _obj5[KTX2TargetFormat.BC7] = (_obj2 = {}, _obj2[DFDTransferFunction.linear] = [
3791
+ engineCore.GLCapabilityType.bptc
3792
+ ], _obj2[DFDTransferFunction.sRGB] = [
3774
3793
  engineCore.GLCapabilityType.bptc
3775
- ], _obj$1[KTX2TargetFormat.BC1_BC3] = [
3794
+ ], _obj2), _obj5[KTX2TargetFormat.BC1_BC3] = (_obj3 = {}, _obj3[DFDTransferFunction.linear] = [
3776
3795
  engineCore.GLCapabilityType.s3tc
3777
- ], _obj$1[KTX2TargetFormat.PVRTC] = [
3796
+ ], _obj3[DFDTransferFunction.sRGB] = [
3797
+ engineCore.GLCapabilityType.s3tc_srgb
3798
+ ], _obj3), _obj5[KTX2TargetFormat.PVRTC] = (_obj4 = {}, _obj4[DFDTransferFunction.linear] = [
3778
3799
  engineCore.GLCapabilityType.pvrtc,
3779
3800
  engineCore.GLCapabilityType.pvrtc_webkit
3780
- ], _obj$1);
3801
+ ], _obj4), _obj5);
3781
3802
  exports.KTX2Loader = __decorate([
3782
3803
  engineCore.resourceLoader(engineCore.AssetType.KTX2, [
3783
3804
  "ktx2"
@@ -4496,7 +4517,7 @@ exports.GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
4496
4517
  if (pbrMetallicRoughness) {
4497
4518
  var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
4498
4519
  if (baseColorFactor) {
4499
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
4520
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToSRGBSpace(baseColorFactor[0]), engineMath.Color.linearToSRGBSpace(baseColorFactor[1]), engineMath.Color.linearToSRGBSpace(baseColorFactor[2]), baseColorFactor[3]);
4500
4521
  }
4501
4522
  if (baseColorTexture) {
4502
4523
  context.get(GLTFParserType.Texture, baseColorTexture.index).then(function(texture) {
@@ -4529,7 +4550,7 @@ exports.GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
4529
4550
  });
4530
4551
  }
4531
4552
  if (emissiveFactor) {
4532
- material.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
4553
+ material.emissiveColor = new engineMath.Color(engineMath.Color.linearToSRGBSpace(emissiveFactor[0]), engineMath.Color.linearToSRGBSpace(emissiveFactor[1]), engineMath.Color.linearToSRGBSpace(emissiveFactor[2]));
4533
4554
  }
4534
4555
  if (normalTexture) {
4535
4556
  var index = normalTexture.index, scale = normalTexture.scale;
@@ -5068,9 +5089,10 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
5068
5089
  var textureInfo = context.glTF.textures[textureIndex];
5069
5090
  var glTFResource = context.glTFResource;
5070
5091
  var sampler = textureInfo.sampler, tmp = textureInfo.source, imageIndex = tmp === void 0 ? 0 : tmp, textureName = textureInfo.name, extensions = textureInfo.extensions;
5071
- var texture = GLTFParser.executeExtensionsCreateAndParse(extensions, context, textureInfo, textureIndex);
5092
+ var isSRGBColorSpace = this._isSRGBColorSpace(textureIndex, context.glTF.materials);
5093
+ var texture = GLTFParser.executeExtensionsCreateAndParse(extensions, context, textureInfo, textureIndex, isSRGBColorSpace);
5072
5094
  if (!texture) {
5073
- texture = GLTFTextureParser._parseTexture(context, imageIndex, textureIndex, sampler, textureName);
5095
+ texture = GLTFTextureParser._parseTexture(context, imageIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
5074
5096
  }
5075
5097
  return engineCore.AssetPromise.resolve(texture).then(function(texture) {
5076
5098
  GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, texture, textureInfo);
@@ -5079,7 +5101,27 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
5079
5101
  return texture;
5080
5102
  });
5081
5103
  };
5082
- /** @internal */ GLTFTextureParser._parseTexture = function _parseTexture(context, imageIndex, textureIndex, sampler, textureName) {
5104
+ _proto._isSRGBColorSpace = function _isSRGBColorSpace(textureIndex, materials) {
5105
+ return materials == null ? void 0 : materials.some(function(material) {
5106
+ var _material_emissiveTexture, _material_pbrMetallicRoughness_baseColorTexture, _material_pbrMetallicRoughness, _material_extensions_KHR_materials_sheen_sheenColorTexture, _material_extensions_KHR_materials_sheen, _material_extensions, _material_extensions_KHR_materials_pbrSpecularGlossiness_diffuseTexture, _material_extensions_KHR_materials_pbrSpecularGlossiness, _material_extensions1, _material_extensions_KHR_materials_pbrSpecularGlossiness_specularGlossinessTexture, _material_extensions_KHR_materials_pbrSpecularGlossiness1, _material_extensions2;
5107
+ if (((_material_emissiveTexture = material.emissiveTexture) == null ? void 0 : _material_emissiveTexture.index) === textureIndex) {
5108
+ return true;
5109
+ }
5110
+ if (((_material_pbrMetallicRoughness = material.pbrMetallicRoughness) == null ? void 0 : (_material_pbrMetallicRoughness_baseColorTexture = _material_pbrMetallicRoughness.baseColorTexture) == null ? void 0 : _material_pbrMetallicRoughness_baseColorTexture.index) === textureIndex) {
5111
+ return true;
5112
+ }
5113
+ if (((_material_extensions = material.extensions) == null ? void 0 : (_material_extensions_KHR_materials_sheen = _material_extensions.KHR_materials_sheen) == null ? void 0 : (_material_extensions_KHR_materials_sheen_sheenColorTexture = _material_extensions_KHR_materials_sheen.sheenColorTexture) == null ? void 0 : _material_extensions_KHR_materials_sheen_sheenColorTexture.index) === textureIndex) {
5114
+ return true;
5115
+ }
5116
+ if (((_material_extensions1 = material.extensions) == null ? void 0 : (_material_extensions_KHR_materials_pbrSpecularGlossiness = _material_extensions1.KHR_materials_pbrSpecularGlossiness) == null ? void 0 : (_material_extensions_KHR_materials_pbrSpecularGlossiness_diffuseTexture = _material_extensions_KHR_materials_pbrSpecularGlossiness.diffuseTexture) == null ? void 0 : _material_extensions_KHR_materials_pbrSpecularGlossiness_diffuseTexture.index) === textureIndex) {
5117
+ return true;
5118
+ }
5119
+ if (((_material_extensions2 = material.extensions) == null ? void 0 : (_material_extensions_KHR_materials_pbrSpecularGlossiness1 = _material_extensions2.KHR_materials_pbrSpecularGlossiness) == null ? void 0 : (_material_extensions_KHR_materials_pbrSpecularGlossiness_specularGlossinessTexture = _material_extensions_KHR_materials_pbrSpecularGlossiness1.specularGlossinessTexture) == null ? void 0 : _material_extensions_KHR_materials_pbrSpecularGlossiness_specularGlossinessTexture.index) === textureIndex) {
5120
+ return true;
5121
+ }
5122
+ });
5123
+ };
5124
+ /** @internal */ GLTFTextureParser._parseTexture = function _parseTexture(context, imageIndex, textureIndex, sampler, textureName, isSRGBColorSpace) {
5083
5125
  var glTFResource = context.glTFResource, glTF = context.glTF;
5084
5126
  var engine = glTFResource.engine, url = glTFResource.url;
5085
5127
  var _glTF_images_imageIndex = glTF.images[imageIndex], uri = _glTF_images_imageIndex.uri, bufferViewIndex = _glTF_images_imageIndex.bufferView, mimeType = _glTF_images_imageIndex.mimeType, imageName = _glTF_images_imageIndex.name;
@@ -5094,7 +5136,8 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
5094
5136
  url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
5095
5137
  type: type,
5096
5138
  params: {
5097
- mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
5139
+ mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap,
5140
+ isSRGBColorSpace: isSRGBColorSpace
5098
5141
  }
5099
5142
  }).onProgress(undefined, context._onTaskDetail).then(function(texture) {
5100
5143
  texture.name = textureName || imageName || texture.name || "texture_" + textureIndex;
@@ -5108,7 +5151,7 @@ exports.GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
5108
5151
  var buffer = buffers[bufferView.buffer];
5109
5152
  var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
5110
5153
  return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
5111
- var texture = new engineCore.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
5154
+ var texture = new engineCore.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap, isSRGBColorSpace);
5112
5155
  texture.setImageSource(image);
5113
5156
  texture.generateMipmaps();
5114
5157
  texture.name = textureName || imageName || "texture_" + textureIndex;
@@ -5373,7 +5416,7 @@ var HDRLoader = /*#__PURE__*/ function(Loader) {
5373
5416
  var bufferArray = new Uint8Array(buffer);
5374
5417
  var _HDRLoader__parseHeader = HDRLoader._parseHeader(bufferArray), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
5375
5418
  var cubeSize = height >> 1;
5376
- texture || (texture = new engineCore.TextureCube(engine, cubeSize));
5419
+ texture || (texture = new engineCore.TextureCube(engine, cubeSize, undefined, undefined, false));
5377
5420
  var pixels = HDRLoader._readPixels(bufferArray.subarray(dataPosition), width, height);
5378
5421
  var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
5379
5422
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
@@ -5933,7 +5976,7 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
5933
5976
  var parsedData = parseSingleKTX(bin);
5934
5977
  var width = parsedData.width, height = parsedData.height, mipmaps = parsedData.mipmaps, engineFormat = parsedData.engineFormat;
5935
5978
  var mipmap = mipmaps.length > 1;
5936
- var texture = new engineCore.Texture2D(resourceManager.engine, width, height, engineFormat, mipmap);
5979
+ var texture = new engineCore.Texture2D(resourceManager.engine, width, height, engineFormat, mipmap, false);
5937
5980
  for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
5938
5981
  var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
5939
5982
  texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
@@ -6375,14 +6418,18 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
6375
6418
  resourceManager// @ts-ignore
6376
6419
  ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(image) {
6377
6420
  var _item_params;
6378
- var _ref = (_item_params = item.params) != null ? _item_params : {}, format = _ref.format, mipmap = _ref.mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
6379
- var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, format, mipmap);
6421
+ 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;
6422
+ var width = image.width, height = image.height;
6423
+ // @ts-ignore
6424
+ var isWebGL2 = resourceManager.engine._hardwareRenderer._isWebGL2;
6425
+ var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(width, height, format, mipmap, isSRGBColorSpace, isWebGL2);
6426
+ var texture = new engineCore.Texture2D(resourceManager.engine, width, height, format, generateMipmap, isSRGBColorSpace);
6380
6427
  texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
6381
6428
  texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
6382
6429
  texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
6383
6430
  texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
6384
6431
  texture.setImageSource(image);
6385
- texture.generateMipmaps();
6432
+ generateMipmap && texture.generateMipmaps();
6386
6433
  if (url.indexOf("data:") !== 0) {
6387
6434
  var index = url.lastIndexOf("/");
6388
6435
  texture.name = url.substring(index + 1);
@@ -6451,16 +6498,25 @@ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
6451
6498
  Promise.all(urls.map(function(url) {
6452
6499
  return resourceManager._request(url, requestConfig);
6453
6500
  })).then(function(images) {
6501
+ var _item_params;
6502
+ 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;
6454
6503
  var _images_ = images[0], width = _images_.width, height = _images_.height;
6504
+ // @ts-ignore
6505
+ var isWebGL2 = resourceManager.engine._hardwareRenderer._isWebGL2;
6455
6506
  if (width !== height) {
6456
6507
  console.error("The cube texture must have the same width and height");
6457
6508
  return;
6458
6509
  }
6459
- var texture = new engineCore.TextureCube(resourceManager.engine, width);
6510
+ var generateMipmap = engineCore.TextureUtils.supportGenerateMipmapsWithCorrection(width, height, format, mipmap, isSRGBColorSpace, isWebGL2);
6511
+ var texture = new engineCore.TextureCube(resourceManager.engine, width, format, generateMipmap, isSRGBColorSpace);
6512
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
6513
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
6514
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
6515
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
6460
6516
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
6461
6517
  texture.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
6462
6518
  }
6463
- texture.generateMipmaps();
6519
+ generateMipmap && texture.generateMipmaps();
6464
6520
  resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
6465
6521
  resolve(texture);
6466
6522
  }).catch(function(e) {
@@ -6873,7 +6929,7 @@ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionPa
6873
6929
  var material = new engineCore.PBRSpecularMaterial(engine);
6874
6930
  var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
6875
6931
  if (diffuseFactor) {
6876
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
6932
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToSRGBSpace(diffuseFactor[0]), engineMath.Color.linearToSRGBSpace(diffuseFactor[1]), engineMath.Color.linearToSRGBSpace(diffuseFactor[2]), diffuseFactor[3]);
6877
6933
  }
6878
6934
  if (diffuseTexture) {
6879
6935
  context.get(GLTFParserType.Texture, diffuseTexture.index).then(function(texture) {
@@ -6884,7 +6940,7 @@ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionPa
6884
6940
  });
6885
6941
  }
6886
6942
  if (specularFactor) {
6887
- material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
6943
+ material.specularColor = new engineMath.Color(engineMath.Color.linearToSRGBSpace(specularFactor[0]), engineMath.Color.linearToSRGBSpace(specularFactor[1]), engineMath.Color.linearToSRGBSpace(specularFactor[2]));
6888
6944
  }
6889
6945
  if (glossinessFactor !== undefined) {
6890
6946
  material.glossiness = glossinessFactor;
@@ -6916,7 +6972,7 @@ var KHR_materials_sheen = /*#__PURE__*/ function(GLTFExtensionParser) {
6916
6972
  _proto.additiveParse = function additiveParse(context, material, schema) {
6917
6973
  var sheenColorFactor = schema.sheenColorFactor, sheenColorTexture = schema.sheenColorTexture, _schema_sheenRoughnessFactor = schema.sheenRoughnessFactor, sheenRoughnessFactor = _schema_sheenRoughnessFactor === void 0 ? 0 : _schema_sheenRoughnessFactor, sheenRoughnessTexture = schema.sheenRoughnessTexture;
6918
6974
  if (sheenColorFactor) {
6919
- material.sheenColor.set(engineMath.Color.linearToGammaSpace(sheenColorFactor[0]), engineMath.Color.linearToGammaSpace(sheenColorFactor[1]), engineMath.Color.linearToGammaSpace(sheenColorFactor[2]), undefined);
6975
+ material.sheenColor.set(engineMath.Color.linearToSRGBSpace(sheenColorFactor[0]), engineMath.Color.linearToSRGBSpace(sheenColorFactor[1]), engineMath.Color.linearToSRGBSpace(sheenColorFactor[2]), undefined);
6920
6976
  }
6921
6977
  material.sheenRoughness = sheenRoughnessFactor;
6922
6978
  if (sheenColorTexture) {
@@ -7031,7 +7087,7 @@ var KHR_materials_volume = /*#__PURE__*/ function(GLTFExtensionParser) {
7031
7087
  material.thickness = thicknessFactor;
7032
7088
  material.attenuationDistance = attenuationDistance;
7033
7089
  if (attenuationColor) {
7034
- material.attenuationColor.set(engineMath.Color.linearToGammaSpace(attenuationColor[0]), engineMath.Color.linearToGammaSpace(attenuationColor[1]), engineMath.Color.linearToGammaSpace(attenuationColor[2]), undefined);
7090
+ material.attenuationColor.set(engineMath.Color.linearToSRGBSpace(attenuationColor[0]), engineMath.Color.linearToSRGBSpace(attenuationColor[1]), engineMath.Color.linearToSRGBSpace(attenuationColor[2]), undefined);
7035
7091
  }
7036
7092
  if (thicknessTexture) {
7037
7093
  exports.GLTFMaterialParser._checkOtherTextureTransform(thicknessTexture, "Thickness texture");
@@ -7093,8 +7149,8 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser) {
7093
7149
  return context.get(GLTFParserType.Buffer, bufferView.buffer).then(function(buffer) {
7094
7150
  var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
7095
7151
  return exports.KTX2Loader._parseBuffer(imageBuffer, engine).then(function(param) {
7096
- var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
7097
- return exports.KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
7152
+ var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
7153
+ return exports.KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
7098
7154
  }).then(function(texture) {
7099
7155
  texture.name = textureName || imageName || "texture_" + bufferViewIndex;
7100
7156
  if (sampler !== undefined) {
@@ -7282,10 +7338,10 @@ var EXT_texture_webp = /*#__PURE__*/ function(GLTFExtensionParser) {
7282
7338
  return _this;
7283
7339
  }
7284
7340
  var _proto = EXT_texture_webp.prototype;
7285
- _proto.createAndParse = function createAndParse(context, schema, textureInfo, textureIndex) {
7341
+ _proto.createAndParse = function createAndParse(context, schema, textureInfo, textureIndex, isSRGBColorSpace) {
7286
7342
  var webPIndex = schema.source;
7287
7343
  var sampler = textureInfo.sampler, tmp = textureInfo.source, fallbackIndex = tmp === void 0 ? 0 : tmp, textureName = textureInfo.name;
7288
- var texture = exports.GLTFTextureParser._parseTexture(context, this._supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName);
7344
+ var texture = exports.GLTFTextureParser._parseTexture(context, this._supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
7289
7345
  return texture;
7290
7346
  };
7291
7347
  return EXT_texture_webp;