From 02e51346f4a7b750ca6de9277a70eda50df911d7 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 18:54:27 +0900 Subject: [PATCH] define ITextureDeserializer --- .../Editor/MeshUtility/TextureSaver.cs | 2 +- .../Extensions/ColorConversionExtensions.cs | 9 +-- .../Runtime/UniGLTF/IO/ImporterContext.cs | 2 +- .../IO/MaterialIO/GltfPbrMaterialImporter.cs | 1 + .../MaterialIO/GltfUnlitMaterialImporter.cs | 2 +- .../UniGLTF/IO/MaterialIO/MaterialExporter.cs | 2 +- .../IO/TextureIO/GltfTextureExporter.cs | 1 + Assets/VRM/Runtime/IO/VRMExporter.cs | 4 +- Assets/VRM/Runtime/IO/VRMMaterialExporter.cs | 2 +- .../IO/Material/Vrm10MToonMaterialExporter.cs | 2 +- .../IO/Material/Vrm10MToonMaterialImporter.cs | 2 +- .../VRM10/Runtime/Migration/MigrationMToon.cs | 2 +- .../GLTF/IO/Editor/EditorTextureSerializer.cs | 2 - .../VRMShaders/GLTF/IO/Runtime/ColorSpace.cs | 4 +- .../GLTF/IO/Runtime/ITextureDeserializer.cs | 11 ++++ .../IO/Runtime/ITextureDeserializer.cs.meta | 3 + .../GLTF/IO/Runtime/ITextureExporter.cs | 2 +- .../GLTF/IO/Runtime/ITextureSerializer.cs | 2 +- .../GLTF/IO/Runtime/NormalConverter.cs | 2 - .../OcclusionMetallicRoughnessConverter.cs | 2 - .../IO/Runtime/RuntimeTextureDeserializer.cs | 22 +++++++ .../RuntimeTextureDeserializer.cs.meta | 3 + .../IO/Runtime/RuntimeTextureSerializer.cs | 2 +- .../GLTF/IO/Runtime/TextureConverter.cs | 3 +- .../GLTF/IO/Runtime/TextureExporter.cs | 3 - .../GLTF/IO/Runtime/TextureFactory.cs | 65 ++++++++----------- .../GLTF/IO/Runtime/TextureImportTypes.cs | 1 - .../GLTF/IO/Tests/CopyTextureTests.cs | 1 - .../GLTF/IO/Tests/TextureBytesTests.cs | 1 - 29 files changed, 88 insertions(+), 72 deletions(-) create mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs create mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs.meta create mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs create mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta diff --git a/Assets/UniGLTF/Editor/MeshUtility/TextureSaver.cs b/Assets/UniGLTF/Editor/MeshUtility/TextureSaver.cs index 90172a28a..a4c050b56 100644 --- a/Assets/UniGLTF/Editor/MeshUtility/TextureSaver.cs +++ b/Assets/UniGLTF/Editor/MeshUtility/TextureSaver.cs @@ -2,7 +2,7 @@ using UnityEditor; using UnityEngine; using VRMShaders; -using ColorSpace = UniGLTF.ColorSpace; +using ColorSpace = VRMShaders.ColorSpace; namespace MeshUtility { diff --git a/Assets/UniGLTF/Runtime/Extensions/ColorConversionExtensions.cs b/Assets/UniGLTF/Runtime/Extensions/ColorConversionExtensions.cs index 0391b4fea..1e6daabe7 100644 --- a/Assets/UniGLTF/Runtime/Extensions/ColorConversionExtensions.cs +++ b/Assets/UniGLTF/Runtime/Extensions/ColorConversionExtensions.cs @@ -1,5 +1,6 @@ using System; using UnityEngine; +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { @@ -10,13 +11,13 @@ namespace UniGLTF var dst = src.ConvertColorSpace(srcColorSpace, dstColorSpace); return new float[] {dst.r, dst.g, dst.b, dst.a}; } - + public static float[] ToFloat3(this Color src, ColorSpace srcColorSpace, ColorSpace dstColorSpace) { var dst = src.ConvertColorSpace(srcColorSpace, dstColorSpace); return new float[] {dst.r, dst.g, dst.b}; } - + public static Color ToColor4(this float[] src, ColorSpace srcColorSpace, ColorSpace dstColorSpace) { if (src == null || src.Length < 4) @@ -27,7 +28,7 @@ namespace UniGLTF return new Color(src[0], src[1], src[2], src[3]).ConvertColorSpace(srcColorSpace, dstColorSpace); } - + public static Color ToColor3(this float[] src, ColorSpace srcColorSpace, ColorSpace dstColorSpace) { if (src == null || src.Length < 3) @@ -64,4 +65,4 @@ namespace UniGLTF } } } -} \ No newline at end of file +} diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 4bd9b196e..53a4b309a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -44,7 +44,7 @@ namespace UniGLTF MaterialDescriptorGenerator = new GltfMaterialDescriptorGenerator(); externalObjectMap = externalObjectMap ?? new Dictionary(); - TextureFactory = new TextureFactory(externalObjectMap + TextureFactory = new TextureFactory(new RuntimeTextureDeserializer(), externalObjectMap .Where(x => x.Value is Texture) .ToDictionary(x => x.Key, x => (Texture) x.Value)); MaterialFactory = new MaterialFactory(externalObjectMap diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfPbrMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfPbrMaterialImporter.cs index b3659431e..6d28cae78 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfPbrMaterialImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfPbrMaterialImporter.cs @@ -1,5 +1,6 @@ using UnityEngine; using VRMShaders; +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs index 0322c9f59..18579b39d 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfUnlitMaterialImporter.cs @@ -1,6 +1,6 @@ using UnityEngine; using VRMShaders; - +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialExporter.cs index b8c6b3216..fdb43e9a6 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialExporter.cs @@ -2,7 +2,7 @@ using UniGLTF.UniUnlit; using UnityEngine; using VRMShaders; - +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureExporter.cs index 3f3cbc637..165ebe058 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureExporter.cs @@ -1,6 +1,7 @@ using System; using UnityEngine; using VRMShaders; +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { diff --git a/Assets/VRM/Runtime/IO/VRMExporter.cs b/Assets/VRM/Runtime/IO/VRMExporter.cs index 2b1e05359..c04c50bd5 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -3,8 +3,8 @@ using System.Linq; using UniGLTF; using UniJSON; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; - +using VRMShaders; +using ColorSpace = VRMShaders.ColorSpace; namespace VRM { diff --git a/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs b/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs index 75a52b895..16dce2440 100644 --- a/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs @@ -5,7 +5,7 @@ using UniGLTF; using UniGLTF.ShaderPropExporter; using UnityEngine; using VRMShaders; -using ColorSpace = UniGLTF.ColorSpace; +using ColorSpace = VRMShaders.ColorSpace; namespace VRM { diff --git a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs index 5c1d8e5f7..f85090c39 100644 --- a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs +++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs @@ -4,7 +4,7 @@ using UniGLTF; using UniGLTF.Extensions.VRMC_materials_mtoon; using UnityEngine; using VRMShaders; -using ColorSpace = UniGLTF.ColorSpace; +using ColorSpace = VRMShaders.ColorSpace; using OutlineWidthMode = MToon.OutlineWidthMode; using RenderMode = MToon.RenderMode; diff --git a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs index d7e2273b1..762f45b05 100644 --- a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs +++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs @@ -4,7 +4,7 @@ using UniGLTF; using UniGLTF.Extensions.VRMC_materials_mtoon; using UnityEngine; using VRMShaders; -using ColorSpace = UniGLTF.ColorSpace; +using ColorSpace = VRMShaders.ColorSpace; using OutlineWidthMode = UniGLTF.Extensions.VRMC_materials_mtoon.OutlineWidthMode; namespace UniVRM10 diff --git a/Assets/VRM10/Runtime/Migration/MigrationMToon.cs b/Assets/VRM10/Runtime/Migration/MigrationMToon.cs index aefa2f380..206a81799 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationMToon.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationMToon.cs @@ -5,7 +5,7 @@ using UniGLTF; using UniGLTF.Extensions.VRMC_materials_mtoon; using UniJSON; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; +using ColorSpace = VRMShaders.ColorSpace; using RenderMode = MToon.RenderMode; namespace UniVRM10 diff --git a/Assets/VRMShaders/GLTF/IO/Editor/EditorTextureSerializer.cs b/Assets/VRMShaders/GLTF/IO/Editor/EditorTextureSerializer.cs index 22386ca1f..3def724cc 100644 --- a/Assets/VRMShaders/GLTF/IO/Editor/EditorTextureSerializer.cs +++ b/Assets/VRMShaders/GLTF/IO/Editor/EditorTextureSerializer.cs @@ -1,10 +1,8 @@ using System; using System.IO; using System.Reflection; -using UniGLTF; using UnityEditor; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ColorSpace.cs b/Assets/VRMShaders/GLTF/IO/Runtime/ColorSpace.cs index 68d124b6e..26332a154 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/ColorSpace.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ColorSpace.cs @@ -1,8 +1,8 @@ -namespace UniGLTF +namespace VRMShaders { public enum ColorSpace { sRGB, Linear, } -} \ No newline at end of file +} diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs new file mode 100644 index 000000000..bb4dd4593 --- /dev/null +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; +using UnityEngine; + +namespace VRMShaders +{ + public interface ITextureDeserializer + { + Task LoadTextureAsync(GetTextureBytesAsync getTextureBytesAsync, bool useMipmap, ColorSpace colorSpace); + } +} diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs.meta b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs.meta new file mode 100644 index 000000000..2522b75ac --- /dev/null +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 47b889c85e814e7eae6f5b7f760c7ef3 +timeCreated: 1622107590 \ No newline at end of file diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs index c0931199b..0e8f30238 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs @@ -13,7 +13,7 @@ namespace VRMShaders /// /// Export する Texture2D のリスト。これが gltf.textures になる /// - IReadOnlyList<(Texture2D, UniGLTF.ColorSpace)> Exported { get; } + IReadOnlyList<(Texture2D, ColorSpace)> Exported { get; } /// /// 指定の Texture を、 sRGB 色空間の値を持つ Texture に出力するように指示する。 diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureSerializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureSerializer.cs index de5e77554..8da1bf82b 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureSerializer.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureSerializer.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace UniGLTF +namespace VRMShaders { /// /// Texture2D を入力として byte[] を得る機能 diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs index 99b8f3281..88180aa2a 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs @@ -1,6 +1,4 @@ using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; - namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/OcclusionMetallicRoughnessConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/OcclusionMetallicRoughnessConverter.cs index 83eaf32ec..3d4635081 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/OcclusionMetallicRoughnessConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/OcclusionMetallicRoughnessConverter.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; - namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs new file mode 100644 index 000000000..aae811f72 --- /dev/null +++ b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs @@ -0,0 +1,22 @@ +using System; +using System.Threading.Tasks; +using UnityEngine; + +namespace VRMShaders +{ + public sealed class RuntimeTextureDeserializer : ITextureDeserializer + { + public async Task LoadTextureAsync(GetTextureBytesAsync getTextureBytesAsync, bool useMipmap, ColorSpace colorSpace) + { + var imageBytes = await getTextureBytesAsync(); + + var texture = new Texture2D(2, 2, TextureFormat.ARGB32, useMipmap, colorSpace == ColorSpace.Linear); + if (imageBytes != null) + { + texture.LoadImage(imageBytes); + } + + return texture; + } + } +} diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta new file mode 100644 index 000000000..d2b98c8a0 --- /dev/null +++ b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 170beedd62e24506acc42b7c04464e84 +timeCreated: 1622107784 \ No newline at end of file diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureSerializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureSerializer.cs index 526e95368..9bbd12e3f 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureSerializer.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureSerializer.cs @@ -2,7 +2,7 @@ using UnityEngine; using VRMShaders; -namespace UniGLTF +namespace VRMShaders { public sealed class RuntimeTextureSerializer : ITextureSerializer { diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs index d9d19b82f..364516842 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; - namespace VRMShaders { @@ -11,6 +9,7 @@ namespace VRMShaders public static Texture2D CreateEmptyTextureWithSettings(Texture src, ColorSpace dstColorSpace, bool dstNeedsAlpha) { var texFormat = dstNeedsAlpha ? TextureFormat.ARGB32 : TextureFormat.RGB24; + texFormat = TextureFormat.ARGB32; var dst = new Texture2D(src.width, src.height, texFormat, src.HasMipMap(), dstColorSpace == ColorSpace.Linear); dst.name = src.name; dst.anisoLevel = src.anisoLevel; diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureExporter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureExporter.cs index 4c46755d8..c4bdb9b2e 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureExporter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureExporter.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using UniGLTF; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; - namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs index ac1258a00..05488f7ce 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs @@ -3,40 +3,40 @@ using System.Collections.Generic; using UnityEngine; using System.Linq; using System.Threading.Tasks; -using ColorSpace = UniGLTF.ColorSpace; - namespace VRMShaders { public class TextureFactory : IDisposable { - private readonly Dictionary m_temporaryTextures = new Dictionary(); - private readonly Dictionary m_textureCache = new Dictionary(); - private readonly IReadOnlyDictionary m_externalMap; + private readonly ITextureDeserializer _textureDeserializer; + private readonly IReadOnlyDictionary _externalMap; + private readonly Dictionary _temporaryTextures = new Dictionary(); + private readonly Dictionary _textureCache = new Dictionary(); /// /// Importer が動的に生成した Texture /// - public IReadOnlyDictionary ConvertedTextures => m_textureCache; + public IReadOnlyDictionary ConvertedTextures => _textureCache; /// - /// + /// 外部から渡された、すでに存在する Texture (ex. Extracted Editor Asset) /// - public IReadOnlyDictionary ExternalTextures => m_externalMap; + public IReadOnlyDictionary ExternalTextures => _externalMap; - public TextureFactory(IReadOnlyDictionary externalTextures) + public TextureFactory(ITextureDeserializer textureDeserializer, IReadOnlyDictionary externalTextures) { - m_externalMap = externalTextures; + _textureDeserializer = textureDeserializer; + _externalMap = externalTextures; } public void Dispose() { - foreach (var kv in m_temporaryTextures) + foreach (var kv in _temporaryTextures) { DestroyResource(kv.Value); } - m_temporaryTextures.Clear(); - m_textureCache.Clear(); + _temporaryTextures.Clear(); + _textureCache.Clear(); } /// @@ -46,7 +46,7 @@ namespace VRMShaders public void TransferOwnership(Func take) { var transferredAssets = new HashSet(); - foreach (var x in m_textureCache) + foreach (var x in _textureCache) { if (take(x.Value)) { @@ -56,23 +56,10 @@ namespace VRMShaders foreach (var key in transferredAssets) { - m_textureCache.Remove(key); + _textureCache.Remove(key); } } - async Task LoadTextureAsync(GetTextureBytesAsync getTextureBytesAsync, bool useMipmap, ColorSpace colorSpace) - { - var imageBytes = await getTextureBytesAsync(); - - var texture = new Texture2D(2, 2, TextureFormat.ARGB32, useMipmap, colorSpace == ColorSpace.Linear); - if (imageBytes != null) - { - texture.LoadImage(imageBytes); - } - - return texture; - } - /// /// テクスチャーをロード、必要であれば変換して返す。 /// 同じものはキャッシュを返す @@ -85,12 +72,12 @@ namespace VRMShaders { var subAssetKey = texDesc.SubAssetKey; - if (m_externalMap != null && m_externalMap.TryGetValue(subAssetKey, out var externalTexture)) + if (_externalMap != null && _externalMap.TryGetValue(subAssetKey, out var externalTexture)) { return externalTexture; } - if (m_textureCache.TryGetValue(subAssetKey, out var cachedTexture)) + if (_textureCache.TryGetValue(subAssetKey, out var cachedTexture)) { return cachedTexture; } @@ -100,11 +87,11 @@ namespace VRMShaders case TextureImportTypes.NormalMap: { // Runtime/SubAsset 用に変換する - var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); var convertedTexture = NormalConverter.Import(rawTexture); convertedTexture.name = subAssetKey.Name; convertedTexture.SetSampler(texDesc.Sampler); - m_textureCache.Add(subAssetKey, convertedTexture); + _textureCache.Add(subAssetKey, convertedTexture); DestroyResource(rawTexture); return convertedTexture; } @@ -116,18 +103,18 @@ namespace VRMShaders if (texDesc.Index0 != null) { - metallicRoughnessTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + metallicRoughnessTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); } if (texDesc.Index1 != null) { - occlusionTexture = await LoadTextureAsync(texDesc.Index1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + occlusionTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); } var combinedTexture = OcclusionMetallicRoughnessConverter.Import(metallicRoughnessTexture, texDesc.MetallicFactor, texDesc.RoughnessFactor, occlusionTexture); combinedTexture.name = subAssetKey.Name; combinedTexture.SetSampler(texDesc.Sampler); - m_textureCache.Add(subAssetKey, combinedTexture); + _textureCache.Add(subAssetKey, combinedTexture); DestroyResource(metallicRoughnessTexture); DestroyResource(occlusionTexture); return combinedTexture; @@ -135,18 +122,18 @@ namespace VRMShaders case TextureImportTypes.sRGB: { - var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB); + var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB); rawTexture.name = subAssetKey.Name; rawTexture.SetSampler(texDesc.Sampler); - m_textureCache.Add(subAssetKey, rawTexture); + _textureCache.Add(subAssetKey, rawTexture); return rawTexture; } case TextureImportTypes.Linear: { - var rawTexture = await LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); rawTexture.name = subAssetKey.Name; rawTexture.SetSampler(texDesc.Sampler); - m_textureCache.Add(subAssetKey, rawTexture); + _textureCache.Add(subAssetKey, rawTexture); return rawTexture; } default: diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureImportTypes.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureImportTypes.cs index d4d1d3c3e..214eb3f2e 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureImportTypes.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureImportTypes.cs @@ -1,6 +1,5 @@ using System; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Tests/CopyTextureTests.cs b/Assets/VRMShaders/GLTF/IO/Tests/CopyTextureTests.cs index 7d7fa051d..daeeeec00 100644 --- a/Assets/VRMShaders/GLTF/IO/Tests/CopyTextureTests.cs +++ b/Assets/VRMShaders/GLTF/IO/Tests/CopyTextureTests.cs @@ -2,7 +2,6 @@ using NUnit.Framework; using UnityEditor; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; namespace VRMShaders { diff --git a/Assets/VRMShaders/GLTF/IO/Tests/TextureBytesTests.cs b/Assets/VRMShaders/GLTF/IO/Tests/TextureBytesTests.cs index 6f5163985..8ce7bc3ea 100644 --- a/Assets/VRMShaders/GLTF/IO/Tests/TextureBytesTests.cs +++ b/Assets/VRMShaders/GLTF/IO/Tests/TextureBytesTests.cs @@ -1,7 +1,6 @@ using NUnit.Framework; using UnityEditor; using UnityEngine; -using ColorSpace = UniGLTF.ColorSpace; namespace VRMShaders {