@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 +100 -44
- package/dist/main.js.map +1 -1
- package/dist/module.js +101 -45
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/Texture2DLoader.d.ts +2 -0
- package/types/gltf/GLTFUtils.d.ts +1 -1
- package/types/gltf/parser/GLTFTextureParser.d.ts +2 -1
- package/types/ktx2/KTX2Container.d.ts +4 -0
- package/types/ktx2/KTX2Loader.d.ts +4 -2
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Utils, AssetPromise, ModelMesh, BlendShape, Texture2D, Loader, Entity, Transform, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ReferResource, Scene, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, AmbientLight, DiffuseMode, TextureCube, TextureFilterMode, TextureCubeFace, request, ContentRestorer, Font, SystemInfo, Animator, Logger, IndexFormat, VertexElementFormat, GLCapabilityType, TextureFormat, InterpolationType, SkinnedMeshRenderer, PBRMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, AnimatorStateMachine, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, AudioClip, AudioManager, ShaderFactory, ShaderLib, PhysicsMaterial, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
|
|
1
|
+
import { Utils, AssetPromise, ModelMesh, BlendShape, Texture2D, Loader, Entity, Transform, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ReferResource, Scene, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, AmbientLight, DiffuseMode, TextureCube, TextureFilterMode, TextureCubeFace, request, ContentRestorer, Font, SystemInfo, Animator, Logger, IndexFormat, VertexElementFormat, GLCapabilityType, TextureFormat, InterpolationType, SkinnedMeshRenderer, PBRMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, AnimatorStateMachine, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, TextureUtils, AudioClip, AudioManager, ShaderFactory, ShaderLib, PhysicsMaterial, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
|
|
2
2
|
import { Color, Vector4, Vector3, Vector2, Quaternion, SphericalHarmonics3, MathUtil, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
|
|
3
3
|
import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
|
|
4
4
|
|
|
@@ -433,9 +433,10 @@ var Texture2DDecoder = /*#__PURE__*/ function() {
|
|
|
433
433
|
var width = bufferReader.nextUint16();
|
|
434
434
|
var height = bufferReader.nextUint16();
|
|
435
435
|
var isPixelBuffer = bufferReader.nextUint8();
|
|
436
|
+
var isSRGBColorSpace = !!bufferReader.nextUint8();
|
|
436
437
|
var mipCount = bufferReader.nextUint8();
|
|
437
438
|
var imagesData = bufferReader.nextImagesData(mipCount);
|
|
438
|
-
var texture2D = new Texture2D(engine, width, height, format, mipmap);
|
|
439
|
+
var texture2D = new Texture2D(engine, width, height, format, mipmap, isSRGBColorSpace);
|
|
439
440
|
texture2D.filterMode = filterMode;
|
|
440
441
|
texture2D.anisoLevel = anisoLevel;
|
|
441
442
|
texture2D.wrapModeU = wrapModeU;
|
|
@@ -1686,7 +1687,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
|
1686
1687
|
var _this;
|
|
1687
1688
|
var shByteLength = 27 * 4;
|
|
1688
1689
|
var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
|
|
1689
|
-
texture || (texture = new TextureCube(engine, size));
|
|
1690
|
+
texture || (texture = new TextureCube(engine, size, undefined, undefined, false));
|
|
1690
1691
|
texture.filterMode = TextureFilterMode.Trilinear;
|
|
1691
1692
|
var mipmapCount = texture.mipmapCount;
|
|
1692
1693
|
var offset = shByteLength + 2;
|
|
@@ -2417,8 +2418,8 @@ var GLTFParserType = /*#__PURE__*/ function(GLTFParserType) {
|
|
|
2417
2418
|
}({});
|
|
2418
2419
|
var _obj$3;
|
|
2419
2420
|
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);
|
|
2420
|
-
var _obj1;
|
|
2421
|
-
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);
|
|
2421
|
+
var _obj1$1;
|
|
2422
|
+
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);
|
|
2422
2423
|
function registerGLTFParser(pipeline) {
|
|
2423
2424
|
return function(Parser) {
|
|
2424
2425
|
var parser = new Parser();
|
|
@@ -2813,6 +2814,11 @@ function registerGLTFParser(pipeline) {
|
|
|
2813
2814
|
return GLTFUtils;
|
|
2814
2815
|
}();
|
|
2815
2816
|
|
|
2817
|
+
var DFDTransferFunction = /*#__PURE__*/ function(DFDTransferFunction) {
|
|
2818
|
+
DFDTransferFunction[DFDTransferFunction["linear"] = 1] = "linear";
|
|
2819
|
+
DFDTransferFunction[DFDTransferFunction["sRGB"] = 2] = "sRGB";
|
|
2820
|
+
return DFDTransferFunction;
|
|
2821
|
+
}({});
|
|
2816
2822
|
var SupercompressionScheme = /*#__PURE__*/ function(SupercompressionScheme) {
|
|
2817
2823
|
SupercompressionScheme[SupercompressionScheme["None"] = 0] = "None";
|
|
2818
2824
|
SupercompressionScheme[SupercompressionScheme["BasisLZ"] = 1] = "BasisLZ";
|
|
@@ -3607,8 +3613,8 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3607
3613
|
type: "arraybuffer"
|
|
3608
3614
|
}).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
|
|
3609
3615
|
return KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then(function(param) {
|
|
3610
|
-
var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
|
|
3611
|
-
return KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
|
|
3616
|
+
var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
|
|
3617
|
+
return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
|
|
3612
3618
|
});
|
|
3613
3619
|
}).then(resolve).catch(reject);
|
|
3614
3620
|
});
|
|
@@ -3642,6 +3648,7 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3642
3648
|
}
|
|
3643
3649
|
return transcodeResultPromise.then(function(result) {
|
|
3644
3650
|
return {
|
|
3651
|
+
ktx2Container: ktx2Container,
|
|
3645
3652
|
engine: engine,
|
|
3646
3653
|
result: result,
|
|
3647
3654
|
targetFormat: targetFormat,
|
|
@@ -3649,7 +3656,7 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3649
3656
|
};
|
|
3650
3657
|
});
|
|
3651
3658
|
};
|
|
3652
|
-
/** @internal */ KTX2Loader._createTextureByBuffer = function _createTextureByBuffer(engine, transcodeResult, targetFormat, params) {
|
|
3659
|
+
/** @internal */ KTX2Loader._createTextureByBuffer = function _createTextureByBuffer(engine, isSRGB, transcodeResult, targetFormat, params) {
|
|
3653
3660
|
var width = transcodeResult.width, height = transcodeResult.height, faces = transcodeResult.faces;
|
|
3654
3661
|
var faceCount = faces.length;
|
|
3655
3662
|
var mipmaps = faces[0];
|
|
@@ -3657,13 +3664,13 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3657
3664
|
var engineFormat = this._getEngineTextureFormat(targetFormat, transcodeResult);
|
|
3658
3665
|
var texture;
|
|
3659
3666
|
if (faceCount !== 6) {
|
|
3660
|
-
texture = new Texture2D(engine, width, height, engineFormat, mipmap);
|
|
3667
|
+
texture = new Texture2D(engine, width, height, engineFormat, mipmap, isSRGB);
|
|
3661
3668
|
for(var mipLevel = 0; mipLevel < mipmaps.length; mipLevel++){
|
|
3662
3669
|
var data = mipmaps[mipLevel].data;
|
|
3663
3670
|
texture.setPixelBuffer(data, mipLevel);
|
|
3664
3671
|
}
|
|
3665
3672
|
} else {
|
|
3666
|
-
texture = new TextureCube(engine, height, engineFormat, mipmap);
|
|
3673
|
+
texture = new TextureCube(engine, height, engineFormat, mipmap, isSRGB);
|
|
3667
3674
|
for(var i = 0; i < faces.length; i++){
|
|
3668
3675
|
var faceData = faces[i];
|
|
3669
3676
|
for(var mipLevel1 = 0; mipLevel1 < mipmaps.length; mipLevel1++){
|
|
@@ -3681,8 +3688,9 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3681
3688
|
};
|
|
3682
3689
|
KTX2Loader._decideTargetFormat = function _decideTargetFormat(engine, ktx2Container, priorityFormats) {
|
|
3683
3690
|
var renderer = engine._hardwareRenderer;
|
|
3684
|
-
var
|
|
3685
|
-
|
|
3691
|
+
var isSRGB = ktx2Container.isSRGB, pixelWidth = ktx2Container.pixelWidth, pixelHeight = ktx2Container.pixelHeight;
|
|
3692
|
+
var targetFormat = this._detectSupportedFormat(renderer, priorityFormats, isSRGB);
|
|
3693
|
+
if (targetFormat === KTX2TargetFormat.PVRTC && (!MathUtil.isPowerOf2(pixelWidth) || !MathUtil.isPowerOf2(pixelHeight) || pixelWidth !== pixelHeight)) {
|
|
3686
3694
|
Logger.warn("PVRTC image need power of 2 and width===height, downgrade to RGBA8");
|
|
3687
3695
|
return KTX2TargetFormat.R8G8B8A8;
|
|
3688
3696
|
}
|
|
@@ -3692,10 +3700,11 @@ var KTX2Loader = /*#__PURE__*/ function(Loader) {
|
|
|
3692
3700
|
}
|
|
3693
3701
|
return targetFormat;
|
|
3694
3702
|
};
|
|
3695
|
-
KTX2Loader._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats) {
|
|
3703
|
+
KTX2Loader._detectSupportedFormat = function _detectSupportedFormat(renderer, priorityFormats, isSRGB) {
|
|
3696
3704
|
for(var i = 0; i < priorityFormats.length; i++){
|
|
3705
|
+
var _this__capabilityMap_format;
|
|
3697
3706
|
var format = priorityFormats[i];
|
|
3698
|
-
var capabilities = this.
|
|
3707
|
+
var capabilities = (_this__capabilityMap_format = this._capabilityMap[format]) == null ? void 0 : _this__capabilityMap_format[isSRGB ? DFDTransferFunction.sRGB : DFDTransferFunction.linear];
|
|
3699
3708
|
if (capabilities) {
|
|
3700
3709
|
for(var j = 0; j < capabilities.length; j++){
|
|
3701
3710
|
if (renderer.canIUse(capabilities[j])) {
|
|
@@ -3761,19 +3770,31 @@ KTX2Loader._priorityFormats = {
|
|
|
3761
3770
|
KTX2TargetFormat.PVRTC
|
|
3762
3771
|
]
|
|
3763
3772
|
};
|
|
3764
|
-
var _obj$1;
|
|
3765
|
-
KTX2Loader.
|
|
3766
|
-
GLCapabilityType.astc
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3773
|
+
var _obj$1, _obj1, _obj2, _obj3, _obj4, _obj5;
|
|
3774
|
+
KTX2Loader._capabilityMap = (_obj5 = {}, _obj5[KTX2TargetFormat.ASTC] = (_obj$1 = {}, _obj$1[DFDTransferFunction.linear] = [
|
|
3775
|
+
GLCapabilityType.astc,
|
|
3776
|
+
GLCapabilityType.astc_webkit
|
|
3777
|
+
], _obj$1[DFDTransferFunction.sRGB] = [
|
|
3778
|
+
GLCapabilityType.astc,
|
|
3779
|
+
GLCapabilityType.astc_webkit
|
|
3780
|
+
], _obj$1), _obj5[KTX2TargetFormat.ETC] = (_obj1 = {}, _obj1[DFDTransferFunction.linear] = [
|
|
3781
|
+
GLCapabilityType.etc,
|
|
3782
|
+
GLCapabilityType.etc_webkit
|
|
3783
|
+
], _obj1[DFDTransferFunction.sRGB] = [
|
|
3784
|
+
GLCapabilityType.etc,
|
|
3785
|
+
GLCapabilityType.etc_webkit
|
|
3786
|
+
], _obj1), _obj5[KTX2TargetFormat.BC7] = (_obj2 = {}, _obj2[DFDTransferFunction.linear] = [
|
|
3787
|
+
GLCapabilityType.bptc
|
|
3788
|
+
], _obj2[DFDTransferFunction.sRGB] = [
|
|
3770
3789
|
GLCapabilityType.bptc
|
|
3771
|
-
],
|
|
3790
|
+
], _obj2), _obj5[KTX2TargetFormat.BC1_BC3] = (_obj3 = {}, _obj3[DFDTransferFunction.linear] = [
|
|
3772
3791
|
GLCapabilityType.s3tc
|
|
3773
|
-
],
|
|
3792
|
+
], _obj3[DFDTransferFunction.sRGB] = [
|
|
3793
|
+
GLCapabilityType.s3tc_srgb
|
|
3794
|
+
], _obj3), _obj5[KTX2TargetFormat.PVRTC] = (_obj4 = {}, _obj4[DFDTransferFunction.linear] = [
|
|
3774
3795
|
GLCapabilityType.pvrtc,
|
|
3775
3796
|
GLCapabilityType.pvrtc_webkit
|
|
3776
|
-
],
|
|
3797
|
+
], _obj4), _obj5);
|
|
3777
3798
|
KTX2Loader = __decorate([
|
|
3778
3799
|
resourceLoader(AssetType.KTX2, [
|
|
3779
3800
|
"ktx2"
|
|
@@ -4492,7 +4513,7 @@ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4492
4513
|
if (pbrMetallicRoughness) {
|
|
4493
4514
|
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
4494
4515
|
if (baseColorFactor) {
|
|
4495
|
-
material.baseColor = new Color(Color.
|
|
4516
|
+
material.baseColor = new Color(Color.linearToSRGBSpace(baseColorFactor[0]), Color.linearToSRGBSpace(baseColorFactor[1]), Color.linearToSRGBSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
4496
4517
|
}
|
|
4497
4518
|
if (baseColorTexture) {
|
|
4498
4519
|
context.get(GLTFParserType.Texture, baseColorTexture.index).then(function(texture) {
|
|
@@ -4525,7 +4546,7 @@ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
4525
4546
|
});
|
|
4526
4547
|
}
|
|
4527
4548
|
if (emissiveFactor) {
|
|
4528
|
-
material.emissiveColor = new Color(Color.
|
|
4549
|
+
material.emissiveColor = new Color(Color.linearToSRGBSpace(emissiveFactor[0]), Color.linearToSRGBSpace(emissiveFactor[1]), Color.linearToSRGBSpace(emissiveFactor[2]));
|
|
4529
4550
|
}
|
|
4530
4551
|
if (normalTexture) {
|
|
4531
4552
|
var index = normalTexture.index, scale = normalTexture.scale;
|
|
@@ -5064,9 +5085,10 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5064
5085
|
var textureInfo = context.glTF.textures[textureIndex];
|
|
5065
5086
|
var glTFResource = context.glTFResource;
|
|
5066
5087
|
var sampler = textureInfo.sampler, tmp = textureInfo.source, imageIndex = tmp === void 0 ? 0 : tmp, textureName = textureInfo.name, extensions = textureInfo.extensions;
|
|
5067
|
-
var
|
|
5088
|
+
var isSRGBColorSpace = this._isSRGBColorSpace(textureIndex, context.glTF.materials);
|
|
5089
|
+
var texture = GLTFParser.executeExtensionsCreateAndParse(extensions, context, textureInfo, textureIndex, isSRGBColorSpace);
|
|
5068
5090
|
if (!texture) {
|
|
5069
|
-
texture = GLTFTextureParser._parseTexture(context, imageIndex, textureIndex, sampler, textureName);
|
|
5091
|
+
texture = GLTFTextureParser._parseTexture(context, imageIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
|
|
5070
5092
|
}
|
|
5071
5093
|
return AssetPromise.resolve(texture).then(function(texture) {
|
|
5072
5094
|
GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, texture, textureInfo);
|
|
@@ -5075,7 +5097,27 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5075
5097
|
return texture;
|
|
5076
5098
|
});
|
|
5077
5099
|
};
|
|
5078
|
-
|
|
5100
|
+
_proto._isSRGBColorSpace = function _isSRGBColorSpace(textureIndex, materials) {
|
|
5101
|
+
return materials == null ? void 0 : materials.some(function(material) {
|
|
5102
|
+
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;
|
|
5103
|
+
if (((_material_emissiveTexture = material.emissiveTexture) == null ? void 0 : _material_emissiveTexture.index) === textureIndex) {
|
|
5104
|
+
return true;
|
|
5105
|
+
}
|
|
5106
|
+
if (((_material_pbrMetallicRoughness = material.pbrMetallicRoughness) == null ? void 0 : (_material_pbrMetallicRoughness_baseColorTexture = _material_pbrMetallicRoughness.baseColorTexture) == null ? void 0 : _material_pbrMetallicRoughness_baseColorTexture.index) === textureIndex) {
|
|
5107
|
+
return true;
|
|
5108
|
+
}
|
|
5109
|
+
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) {
|
|
5110
|
+
return true;
|
|
5111
|
+
}
|
|
5112
|
+
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) {
|
|
5113
|
+
return true;
|
|
5114
|
+
}
|
|
5115
|
+
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) {
|
|
5116
|
+
return true;
|
|
5117
|
+
}
|
|
5118
|
+
});
|
|
5119
|
+
};
|
|
5120
|
+
/** @internal */ GLTFTextureParser._parseTexture = function _parseTexture(context, imageIndex, textureIndex, sampler, textureName, isSRGBColorSpace) {
|
|
5079
5121
|
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
5080
5122
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
5081
5123
|
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;
|
|
@@ -5090,7 +5132,8 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5090
5132
|
url: Utils.resolveAbsoluteUrl(url, uri),
|
|
5091
5133
|
type: type,
|
|
5092
5134
|
params: {
|
|
5093
|
-
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
5135
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap,
|
|
5136
|
+
isSRGBColorSpace: isSRGBColorSpace
|
|
5094
5137
|
}
|
|
5095
5138
|
}).onProgress(undefined, context._onTaskDetail).then(function(texture) {
|
|
5096
5139
|
texture.name = textureName || imageName || texture.name || "texture_" + textureIndex;
|
|
@@ -5104,7 +5147,7 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser1) {
|
|
|
5104
5147
|
var buffer = buffers[bufferView.buffer];
|
|
5105
5148
|
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
5106
5149
|
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
5107
|
-
var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
5150
|
+
var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap, isSRGBColorSpace);
|
|
5108
5151
|
texture.setImageSource(image);
|
|
5109
5152
|
texture.generateMipmaps();
|
|
5110
5153
|
texture.name = textureName || imageName || "texture_" + textureIndex;
|
|
@@ -5369,7 +5412,7 @@ var HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5369
5412
|
var bufferArray = new Uint8Array(buffer);
|
|
5370
5413
|
var _HDRLoader__parseHeader = HDRLoader._parseHeader(bufferArray), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
|
|
5371
5414
|
var cubeSize = height >> 1;
|
|
5372
|
-
texture || (texture = new TextureCube(engine, cubeSize));
|
|
5415
|
+
texture || (texture = new TextureCube(engine, cubeSize, undefined, undefined, false));
|
|
5373
5416
|
var pixels = HDRLoader._readPixels(bufferArray.subarray(dataPosition), width, height);
|
|
5374
5417
|
var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
|
|
5375
5418
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
@@ -5929,7 +5972,7 @@ var KTXLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5929
5972
|
var parsedData = parseSingleKTX(bin);
|
|
5930
5973
|
var width = parsedData.width, height = parsedData.height, mipmaps = parsedData.mipmaps, engineFormat = parsedData.engineFormat;
|
|
5931
5974
|
var mipmap = mipmaps.length > 1;
|
|
5932
|
-
var texture = new Texture2D(resourceManager.engine, width, height, engineFormat, mipmap);
|
|
5975
|
+
var texture = new Texture2D(resourceManager.engine, width, height, engineFormat, mipmap, false);
|
|
5933
5976
|
for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
|
|
5934
5977
|
var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
|
|
5935
5978
|
texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
|
|
@@ -6371,14 +6414,18 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6371
6414
|
resourceManager// @ts-ignore
|
|
6372
6415
|
._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(image) {
|
|
6373
6416
|
var _item_params;
|
|
6374
|
-
var _ref = (_item_params = item.params) != null ? _item_params : {},
|
|
6375
|
-
var
|
|
6417
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? 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;
|
|
6418
|
+
var width = image.width, height = image.height;
|
|
6419
|
+
// @ts-ignore
|
|
6420
|
+
var isWebGL2 = resourceManager.engine._hardwareRenderer._isWebGL2;
|
|
6421
|
+
var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(width, height, format, mipmap, isSRGBColorSpace, isWebGL2);
|
|
6422
|
+
var texture = new Texture2D(resourceManager.engine, width, height, format, generateMipmap, isSRGBColorSpace);
|
|
6376
6423
|
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6377
6424
|
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6378
6425
|
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6379
6426
|
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6380
6427
|
texture.setImageSource(image);
|
|
6381
|
-
texture.generateMipmaps();
|
|
6428
|
+
generateMipmap && texture.generateMipmaps();
|
|
6382
6429
|
if (url.indexOf("data:") !== 0) {
|
|
6383
6430
|
var index = url.lastIndexOf("/");
|
|
6384
6431
|
texture.name = url.substring(index + 1);
|
|
@@ -6447,16 +6494,25 @@ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6447
6494
|
Promise.all(urls.map(function(url) {
|
|
6448
6495
|
return resourceManager._request(url, requestConfig);
|
|
6449
6496
|
})).then(function(images) {
|
|
6497
|
+
var _item_params;
|
|
6498
|
+
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? 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;
|
|
6450
6499
|
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
6500
|
+
// @ts-ignore
|
|
6501
|
+
var isWebGL2 = resourceManager.engine._hardwareRenderer._isWebGL2;
|
|
6451
6502
|
if (width !== height) {
|
|
6452
6503
|
console.error("The cube texture must have the same width and height");
|
|
6453
6504
|
return;
|
|
6454
6505
|
}
|
|
6455
|
-
var
|
|
6506
|
+
var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(width, height, format, mipmap, isSRGBColorSpace, isWebGL2);
|
|
6507
|
+
var texture = new TextureCube(resourceManager.engine, width, format, generateMipmap, isSRGBColorSpace);
|
|
6508
|
+
texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
|
|
6509
|
+
texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
|
|
6510
|
+
texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
|
|
6511
|
+
texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
|
|
6456
6512
|
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
6457
6513
|
texture.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
6458
6514
|
}
|
|
6459
|
-
texture.generateMipmaps();
|
|
6515
|
+
generateMipmap && texture.generateMipmaps();
|
|
6460
6516
|
resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
|
|
6461
6517
|
resolve(texture);
|
|
6462
6518
|
}).catch(function(e) {
|
|
@@ -6869,7 +6925,7 @@ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionPa
|
|
|
6869
6925
|
var material = new PBRSpecularMaterial(engine);
|
|
6870
6926
|
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
6871
6927
|
if (diffuseFactor) {
|
|
6872
|
-
material.baseColor = new Color(Color.
|
|
6928
|
+
material.baseColor = new Color(Color.linearToSRGBSpace(diffuseFactor[0]), Color.linearToSRGBSpace(diffuseFactor[1]), Color.linearToSRGBSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
6873
6929
|
}
|
|
6874
6930
|
if (diffuseTexture) {
|
|
6875
6931
|
context.get(GLTFParserType.Texture, diffuseTexture.index).then(function(texture) {
|
|
@@ -6880,7 +6936,7 @@ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionPa
|
|
|
6880
6936
|
});
|
|
6881
6937
|
}
|
|
6882
6938
|
if (specularFactor) {
|
|
6883
|
-
material.specularColor = new Color(Color.
|
|
6939
|
+
material.specularColor = new Color(Color.linearToSRGBSpace(specularFactor[0]), Color.linearToSRGBSpace(specularFactor[1]), Color.linearToSRGBSpace(specularFactor[2]));
|
|
6884
6940
|
}
|
|
6885
6941
|
if (glossinessFactor !== undefined) {
|
|
6886
6942
|
material.glossiness = glossinessFactor;
|
|
@@ -6912,7 +6968,7 @@ var KHR_materials_sheen = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
|
6912
6968
|
_proto.additiveParse = function additiveParse(context, material, schema) {
|
|
6913
6969
|
var sheenColorFactor = schema.sheenColorFactor, sheenColorTexture = schema.sheenColorTexture, _schema_sheenRoughnessFactor = schema.sheenRoughnessFactor, sheenRoughnessFactor = _schema_sheenRoughnessFactor === void 0 ? 0 : _schema_sheenRoughnessFactor, sheenRoughnessTexture = schema.sheenRoughnessTexture;
|
|
6914
6970
|
if (sheenColorFactor) {
|
|
6915
|
-
material.sheenColor.set(Color.
|
|
6971
|
+
material.sheenColor.set(Color.linearToSRGBSpace(sheenColorFactor[0]), Color.linearToSRGBSpace(sheenColorFactor[1]), Color.linearToSRGBSpace(sheenColorFactor[2]), undefined);
|
|
6916
6972
|
}
|
|
6917
6973
|
material.sheenRoughness = sheenRoughnessFactor;
|
|
6918
6974
|
if (sheenColorTexture) {
|
|
@@ -7027,7 +7083,7 @@ var KHR_materials_volume = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
|
7027
7083
|
material.thickness = thicknessFactor;
|
|
7028
7084
|
material.attenuationDistance = attenuationDistance;
|
|
7029
7085
|
if (attenuationColor) {
|
|
7030
|
-
material.attenuationColor.set(Color.
|
|
7086
|
+
material.attenuationColor.set(Color.linearToSRGBSpace(attenuationColor[0]), Color.linearToSRGBSpace(attenuationColor[1]), Color.linearToSRGBSpace(attenuationColor[2]), undefined);
|
|
7031
7087
|
}
|
|
7032
7088
|
if (thicknessTexture) {
|
|
7033
7089
|
GLTFMaterialParser._checkOtherTextureTransform(thicknessTexture, "Thickness texture");
|
|
@@ -7089,8 +7145,8 @@ var KHR_texture_basisu = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
|
7089
7145
|
return context.get(GLTFParserType.Buffer, bufferView.buffer).then(function(buffer) {
|
|
7090
7146
|
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
7091
7147
|
return KTX2Loader._parseBuffer(imageBuffer, engine).then(function(param) {
|
|
7092
|
-
var engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
|
|
7093
|
-
return KTX2Loader._createTextureByBuffer(engine, result, targetFormat, params);
|
|
7148
|
+
var ktx2Container = param.ktx2Container, engine = param.engine, result = param.result, targetFormat = param.targetFormat, params = param.params;
|
|
7149
|
+
return KTX2Loader._createTextureByBuffer(engine, ktx2Container.isSRGB, result, targetFormat, params);
|
|
7094
7150
|
}).then(function(texture) {
|
|
7095
7151
|
texture.name = textureName || imageName || "texture_" + bufferViewIndex;
|
|
7096
7152
|
if (sampler !== undefined) {
|
|
@@ -7278,10 +7334,10 @@ var EXT_texture_webp = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
|
7278
7334
|
return _this;
|
|
7279
7335
|
}
|
|
7280
7336
|
var _proto = EXT_texture_webp.prototype;
|
|
7281
|
-
_proto.createAndParse = function createAndParse(context, schema, textureInfo, textureIndex) {
|
|
7337
|
+
_proto.createAndParse = function createAndParse(context, schema, textureInfo, textureIndex, isSRGBColorSpace) {
|
|
7282
7338
|
var webPIndex = schema.source;
|
|
7283
7339
|
var sampler = textureInfo.sampler, tmp = textureInfo.source, fallbackIndex = tmp === void 0 ? 0 : tmp, textureName = textureInfo.name;
|
|
7284
|
-
var texture = GLTFTextureParser._parseTexture(context, this._supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName);
|
|
7340
|
+
var texture = GLTFTextureParser._parseTexture(context, this._supportWebP ? webPIndex : fallbackIndex, textureIndex, sampler, textureName, isSRGBColorSpace);
|
|
7285
7341
|
return texture;
|
|
7286
7342
|
};
|
|
7287
7343
|
return EXT_texture_webp;
|