From 02e51346f4a7b750ca6de9277a70eda50df911d7 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 18:54:27 +0900 Subject: [PATCH 1/6] 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 90172a28a6..a4c050b565 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 0391b4fea7..1e6daabe7e 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 @@ public static float[] ToFloat4(this Color src, ColorSpace srcColorSpace, ColorSp 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 @@ public static Color ToColor4(this float[] src, ColorSpace srcColorSpace, ColorSp 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 @@ private static Color ConvertColorSpace(this Color srcColor, ColorSpace srcColorS } } } -} \ 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 4bd9b196e2..53a4b309a1 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -44,7 +44,7 @@ public ImporterContext(GltfParser parser, IReadOnlyDictionary(); - 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 b3659431e6..6d28cae78a 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 0322c9f595..18579b39da 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 b8c6b32161..fdb43e9a61 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 3f3cbc6377..165ebe058c 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 2b1e05359c..c04c50bd52 100644 --- a/Assets/VRM/Runtime/IO/VRMExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMExporter.cs @@ -3,8 +3,8 @@ 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 75a52b895c..16dce2440b 100644 --- a/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs +++ b/Assets/VRM/Runtime/IO/VRMMaterialExporter.cs @@ -5,7 +5,7 @@ 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 5c1d8e5f75..f85090c39d 100644 --- a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs +++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialExporter.cs @@ -4,7 +4,7 @@ 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 d7e2273b17..762f45b05e 100644 --- a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs +++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs @@ -4,7 +4,7 @@ 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 aefa2f3806..206a817997 100644 --- a/Assets/VRM10/Runtime/Migration/MigrationMToon.cs +++ b/Assets/VRM10/Runtime/Migration/MigrationMToon.cs @@ -5,7 +5,7 @@ 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 22386ca1f9..3def724ccb 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 68d124b6e2..26332a1547 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 0000000000..bb4dd4593d --- /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 0000000000..2522b75ace --- /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 c0931199bc..0e8f302384 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureExporter.cs @@ -13,7 +13,7 @@ public interface ITextureExporter /// /// 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 de5e775549..8da1bf82b3 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 99b8f32815..88180aa2a5 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 83eaf32ecd..3d4635081c 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 0000000000..aae811f729 --- /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 0000000000..d2b98c8a0e --- /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 526e953682..9bbd12e3f0 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 d9d19b82f2..364516842a 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 @@ public static class TextureConverter 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 4c46755d86..c4bdb9b2e7 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 ac1258a008..05488f7cea 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs @@ -3,40 +3,40 @@ 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 @@ public void Dispose() 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,21 +56,8 @@ public void TransferOwnership(Func take) foreach (var key in transferredAssets) { - m_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); + _textureCache.Remove(key); } - - return texture; } /// @@ -85,12 +72,12 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) { 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 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) 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 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) 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 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) 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 d4d1d3c3ef..214eb3f2ed 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 7d7fa051d0..daeeeec00c 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 6f51639859..8ce7bc3ea0 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 { From 6b6a219d431b988774c9abbdb1db0d91327bc70a Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 20:03:45 +0900 Subject: [PATCH 2/6] use ITextureDeserializer --- .../Runtime/UniGLTF/IO/ImporterContext.cs | 9 ++++++-- .../GLTF/IO/Runtime/ITextureDeserializer.cs | 12 +++++++++- .../IO/Runtime/RuntimeTextureDeserializer.cs | 22 ------------------ .../GLTF/IO/Runtime/TextureFactory.cs | 15 ++++++++---- .../IO/Runtime/UnityTextureDeserializer.cs | 23 +++++++++++++++++++ ....meta => UnityTextureDeserializer.cs.meta} | 0 6 files changed, 51 insertions(+), 30 deletions(-) delete mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs create mode 100644 Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs rename Assets/VRMShaders/GLTF/IO/Runtime/{RuntimeTextureDeserializer.cs.meta => UnityTextureDeserializer.cs.meta} (100%) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 53a4b309a1..34683b75b1 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -37,14 +37,19 @@ public IAnimationImporter AnimationImporter public TextureFactory TextureFactory { get; } public MaterialFactory MaterialFactory { get; } - public ImporterContext(GltfParser parser, IReadOnlyDictionary externalObjectMap = null) + public ImporterContext( + GltfParser parser, + IReadOnlyDictionary externalObjectMap = null, + ITextureDeserializer textureDeserializer = null) { Parser = parser; TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Parser); MaterialDescriptorGenerator = new GltfMaterialDescriptorGenerator(); externalObjectMap = externalObjectMap ?? new Dictionary(); - TextureFactory = new TextureFactory(new RuntimeTextureDeserializer(), externalObjectMap + textureDeserializer = textureDeserializer ?? new UnityTextureDeserializer(); + + TextureFactory = new TextureFactory(textureDeserializer, externalObjectMap .Where(x => x.Value is Texture) .ToDictionary(x => x.Key, x => (Texture) x.Value)); MaterialFactory = new MaterialFactory(externalObjectMap diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs index bb4dd4593d..7551898b95 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/ITextureDeserializer.cs @@ -4,8 +4,18 @@ namespace VRMShaders { + /// + /// 単純に Texture2D アセットを生成する機能 + /// public interface ITextureDeserializer { - Task LoadTextureAsync(GetTextureBytesAsync getTextureBytesAsync, bool useMipmap, ColorSpace colorSpace); + /// + /// imageData をもとに Texture2D を生成する + /// + /// データ + /// Texture2D の mipmap が生成されるべきか否か + /// Texture2D の色空間 + /// + Task LoadTextureAsync(byte[] imageData, bool useMipmap, ColorSpace colorSpace); } } diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs deleted file mode 100644 index aae811f729..0000000000 --- a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/TextureFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs index 05488f7cea..bf2f34425e 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs @@ -87,7 +87,8 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) case TextureImportTypes.NormalMap: { // Runtime/SubAsset 用に変換する - var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var data0 = await texDesc.Index0(); + var rawTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); var convertedTexture = NormalConverter.Import(rawTexture); convertedTexture.name = subAssetKey.Name; convertedTexture.SetSampler(texDesc.Sampler); @@ -103,11 +104,13 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) if (texDesc.Index0 != null) { - metallicRoughnessTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var data0 = await texDesc.Index0(); + metallicRoughnessTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); } if (texDesc.Index1 != null) { - occlusionTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var data1 = await texDesc.Index1(); + occlusionTexture = await _textureDeserializer.LoadTextureAsync(data1, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); } var combinedTexture = OcclusionMetallicRoughnessConverter.Import(metallicRoughnessTexture, @@ -122,7 +125,8 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) case TextureImportTypes.sRGB: { - var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB); + var data0 = await texDesc.Index0(); + var rawTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.sRGB); rawTexture.name = subAssetKey.Name; rawTexture.SetSampler(texDesc.Sampler); _textureCache.Add(subAssetKey, rawTexture); @@ -130,7 +134,8 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) } case TextureImportTypes.Linear: { - var rawTexture = await _textureDeserializer.LoadTextureAsync(texDesc.Index0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); + var data0 = await texDesc.Index0(); + var rawTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); rawTexture.name = subAssetKey.Name; rawTexture.SetSampler(texDesc.Sampler); _textureCache.Add(subAssetKey, rawTexture); diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs b/Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs new file mode 100644 index 0000000000..ad84c9bc5d --- /dev/null +++ b/Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using UnityEngine; + +namespace VRMShaders +{ + /// + /// Unity の ImageConversion.LoadImage を用いて PNG/JPG の読み込みを実現する + /// + public sealed class UnityTextureDeserializer : ITextureDeserializer + { + public async Task LoadTextureAsync(byte[] imageData, bool useMipmap, ColorSpace colorSpace) + { + var texture = new Texture2D(2, 2, TextureFormat.ARGB32, useMipmap, colorSpace == ColorSpace.Linear); + if (imageData != null) + { + texture.LoadImage(imageData); + } + + return texture; + } + } +} diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta b/Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs.meta similarity index 100% rename from Assets/VRMShaders/GLTF/IO/Runtime/RuntimeTextureDeserializer.cs.meta rename to Assets/VRMShaders/GLTF/IO/Runtime/UnityTextureDeserializer.cs.meta From 44bced7f3db3beb8be669ff9f578f79f3b5e42d0 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 20:27:11 +0900 Subject: [PATCH 3/6] don't need normal texture conversion when importing --- .../Resources/Shaders/NormalMapEncoder.shader | 68 ------------------- .../Shaders/NormalMapEncoder.shader.meta | 9 --- .../GLTF/IO/Runtime/NormalConverter.cs | 17 +---- .../GLTF/IO/Runtime/TextureFactory.cs | 23 +++---- 4 files changed, 11 insertions(+), 106 deletions(-) delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader delete mode 100644 Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader b/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader deleted file mode 100644 index 8c77bb20b8..0000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader +++ /dev/null @@ -1,68 +0,0 @@ -Shader "UniGLTF/NormalMapEncoder" -{ - Properties - { - _MainTex("Texture", 2D) = "white" {} - } - SubShader - { - // No culling or depth - Cull Off ZWrite Off ZTest Always - - Pass - { - CGPROGRAM - #pragma vertex vert - #pragma fragment frag - - #include "UnityCG.cginc" - - struct appdata - { - float4 vertex : POSITION; - float2 uv : TEXCOORD0; - }; - - struct v2f - { - float2 uv : TEXCOORD0; - float4 vertex : SV_POSITION; - }; - - v2f vert(appdata v) - { - v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.uv = v.uv; - return o; - } - - sampler2D _MainTex; - - fixed4 frag(v2f i) : SV_Target - { - half4 col = tex2D(_MainTex, i.uv); - - half4 packedNormal; - packedNormal.x = col.x; - packedNormal.y = col.y; - packedNormal.z = col.z; - packedNormal.w = 1.0; - - // normalize as normal vector - float3 normal; - normal.xy = packedNormal.xy * 2 - 1; - if (dot(normal.xy, normal.xy) > 1) - { - normal.xy = normalize(normal.xy); - } - normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); - - packedNormal.xyz = normal.xyz * 0.5 + 0.5; - return packedNormal; - } - ENDCG - } - } -} - diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta b/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta deleted file mode 100644 index d0ef10022d..0000000000 --- a/Assets/UniGLTF/Runtime/UniGLTF/Resources/Shaders/NormalMapEncoder.shader.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 3e39586253f31b34f87fa7e133449b1e -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs index 88180aa2a5..bd9ea9bf6e 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs @@ -17,28 +17,13 @@ private static Material Decoder } } - private static Material m_encoder; - private static Material Encoder - { - get - { - if (m_encoder == null) - { - m_encoder = new Material(Shader.Find("UniGLTF/NormalMapEncoder")); - } - return m_encoder; - } - } - // GLTF data to Unity texture - // ConvertToNormalValueFromRawColorWhenCompressionIsRequired public static Texture2D Import(Texture2D texture) { - return TextureConverter.CopyTexture(texture, ColorSpace.Linear, false, Encoder); + return texture; } // Unity texture to GLTF data - // ConvertToRawColorWhenNormalValueIsCompressed public static Texture2D Export(Texture texture) { return TextureConverter.CopyTexture(texture, ColorSpace.Linear, false, Decoder); diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs index bf2f34425e..d3bc48f0c6 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureFactory.cs @@ -61,13 +61,9 @@ public void TransferOwnership(Func take) } /// - /// テクスチャーをロード、必要であれば変換して返す。 - /// 同じものはキャッシュを返す + /// テクスチャ生成情報を基に、テクスチャ生成を行う。 + /// SubAssetKey が同じ場合はキャッシュを返す。 /// - /// 変換の有無を判断する: METALLIC_GLOSS_PROP - /// METALLIC_GLOSS_PROPの追加パラメーター - /// gltf の texture index - /// public async Task GetTextureAsync(TextureDescriptor texDesc) { var subAssetKey = texDesc.SubAssetKey; @@ -86,15 +82,16 @@ public async Task GetTextureAsync(TextureDescriptor texDesc) { case TextureImportTypes.NormalMap: { - // Runtime/SubAsset 用に変換する + // no conversion. Unity's normal map is same with glTF's. + // + // > contrary to Unity’s usual convention of using Y as “up” + // https://docs.unity3d.com/2018.4/Documentation/Manual/StandardShaderMaterialParameterNormalMap.html var data0 = await texDesc.Index0(); var rawTexture = await _textureDeserializer.LoadTextureAsync(data0, texDesc.Sampler.EnableMipMap, ColorSpace.Linear); - var convertedTexture = NormalConverter.Import(rawTexture); - convertedTexture.name = subAssetKey.Name; - convertedTexture.SetSampler(texDesc.Sampler); - _textureCache.Add(subAssetKey, convertedTexture); - DestroyResource(rawTexture); - return convertedTexture; + rawTexture.name = subAssetKey.Name; + rawTexture.SetSampler(texDesc.Sampler); + _textureCache.Add(subAssetKey, rawTexture); + return rawTexture; } case TextureImportTypes.StandardMap: From 7c9be3cf9e54511a4832584d09c62eeff7f0fd71 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 21:24:46 +0900 Subject: [PATCH 4/6] remove debug code --- Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs index 364516842a..e53fdd1599 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/TextureConverter.cs @@ -9,7 +9,6 @@ public static class TextureConverter 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; From de55fd46376f033d75b29add3ff00e1c404d586c Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 21:25:26 +0900 Subject: [PATCH 5/6] remove unused --- Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs index bd9ea9bf6e..d87b40ff4b 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/NormalConverter.cs @@ -17,12 +17,6 @@ private static Material Decoder } } - // GLTF data to Unity texture - public static Texture2D Import(Texture2D texture) - { - return texture; - } - // Unity texture to GLTF data public static Texture2D Export(Texture texture) { From 9d0592088a17377b1ee19529f63efc872ddbd6b6 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 27 May 2021 21:32:11 +0900 Subject: [PATCH 6/6] Add argument to VRM & VRM10 ImporterContext --- Assets/VRM/Runtime/IO/VRMImporterContext.cs | 7 +++++-- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Assets/VRM/Runtime/IO/VRMImporterContext.cs b/Assets/VRM/Runtime/IO/VRMImporterContext.cs index bab16713b5..f2fcca636e 100644 --- a/Assets/VRM/Runtime/IO/VRMImporterContext.cs +++ b/Assets/VRM/Runtime/IO/VRMImporterContext.cs @@ -20,8 +20,11 @@ public NotVrm0Exception() public VRM.glTF_VRM_extensions VRM { get; private set; } - public VRMImporterContext(GltfParser parser, IReadOnlyDictionary externalObjectMap = null) - : base(parser, externalObjectMap) + public VRMImporterContext( + GltfParser parser, + IReadOnlyDictionary externalObjectMap = null, + ITextureDeserializer textureDeserializer = null) + : base(parser, externalObjectMap, textureDeserializer) { // parse VRM part if (glTF_VRM_extensions.TryDeserialize(GLTF.extensions, out glTF_VRM_extensions vrm)) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 34cc7e62a3..67cfbb8212 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -21,8 +21,11 @@ public class Vrm10Importer : UniGLTF.ImporterContext IReadOnlyDictionary m_externalMap; - public Vrm10Importer(UniGLTF.GltfParser parser, IReadOnlyDictionary externalObjectMap = null) - : base(parser, externalObjectMap) + public Vrm10Importer( + UniGLTF.GltfParser parser, + IReadOnlyDictionary externalObjectMap = null, + ITextureDeserializer textureDeserializer = null) + : base(parser, externalObjectMap, textureDeserializer) { TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(parser); MaterialDescriptorGenerator = new Vrm10MaterialDescriptorGenerator();