diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMaterial.cs b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMaterial.cs
index 4fe7602504..bb58c35bd2 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMaterial.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/Format/glTFMaterial.cs
@@ -3,21 +3,8 @@
namespace UniGLTF
{
- public enum glTFTextureTypes
- {
- OcclusionMetallicRoughness,
- Normal,
- SRGB,
- Linear,
- }
-
- public interface IglTFTextureinfo
- {
- glTFTextureTypes TextureType { get; }
- }
-
[Serializable]
- public abstract class glTFTextureInfo : IglTFTextureinfo
+ public abstract class glTFTextureInfo
{
[JsonSchema(Required = true, Minimum = 0)]
public int index = -1;
@@ -28,32 +15,22 @@ public abstract class glTFTextureInfo : IglTFTextureinfo
// empty schemas
public glTFExtension extensions;
public glTFExtension extras;
-
- public abstract glTFTextureTypes TextureType { get; }
}
-
[Serializable]
public class glTFMaterialBaseColorTextureInfo : glTFTextureInfo
{
- public override glTFTextureTypes TextureType => glTFTextureTypes.SRGB;
}
[Serializable]
public class glTFMaterialMetallicRoughnessTextureInfo : glTFTextureInfo
{
- public override glTFTextureTypes TextureType => glTFTextureTypes.OcclusionMetallicRoughness;
}
[Serializable]
public class glTFMaterialNormalTextureInfo : glTFTextureInfo
{
public float scale = 1.0f;
-
- public override glTFTextureTypes TextureType
- {
- get { return glTFTextureTypes.Normal; }
- }
}
[Serializable]
@@ -61,14 +38,11 @@ public class glTFMaterialOcclusionTextureInfo : glTFTextureInfo
{
[JsonSchema(Minimum = 0.0, Maximum = 1.0)]
public float strength = 1.0f;
-
- public override glTFTextureTypes TextureType => glTFTextureTypes.OcclusionMetallicRoughness;
}
[Serializable]
public class glTFMaterialEmissiveTextureInfo : glTFTextureInfo
{
- public override glTFTextureTypes TextureType => glTFTextureTypes.SRGB;
}
[Serializable]
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfMaterialImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfMaterialImporter.cs
index b038d61801..5c001e4997 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfMaterialImporter.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfMaterialImporter.cs
@@ -53,21 +53,35 @@ public MaterialImportParam GetMaterialParam(GltfParser parser, int i)
public static (Vector2, Vector2) GetTextureOffsetAndScale(glTFTextureInfo textureInfo)
{
- Vector2 offset = new Vector2(0, 0);
- Vector2 scale = new Vector2(1, 1);
- if (glTF_KHR_texture_transform.TryGet(textureInfo, out glTF_KHR_texture_transform textureTransform))
+ if (glTF_KHR_texture_transform.TryGet(textureInfo, out var textureTransform))
+ {
+ return GetTextureOffsetAndScale(textureTransform);
+ }
+ return (new Vector2(0, 0), new Vector2(1, 1));
+ }
+
+ public static (Vector2, Vector2) GetTextureOffsetAndScale(glTF_KHR_texture_transform textureTransform)
+ {
+ var offset = new Vector2(0, 0);
+ var scale = new Vector2(1, 1);
+
+ if (textureTransform != null)
{
if (textureTransform.offset != null && textureTransform.offset.Length == 2)
{
offset = new Vector2(textureTransform.offset[0], textureTransform.offset[1]);
}
+
if (textureTransform.scale != null && textureTransform.scale.Length == 2)
{
scale = new Vector2(textureTransform.scale[0], textureTransform.scale[1]);
}
-
- offset.y = (offset.y + scale.y - 1.0f) * -1.0f;
+
+ // Coordinate Conversion: GL (top-left origin) to DX (bottom-left origin)
+ // Formula: https://github.com/vrm-c/UniVRM/issues/930
+ offset.y = 1.0f - offset.y - scale.y;
}
+
return (offset, scale);
}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs
index 7596e09692..258b13b35f 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/GltfTextureEnumerator.cs
@@ -28,7 +28,7 @@ namespace UniGLTF
///
public static class GltfTextureEnumerator
{
- public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateTexturesForMaterial(GltfParser parser, int i)
+ public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateTexturesReferencedByMaterials(GltfParser parser, int i)
{
var m = parser.GLTF.materials[i];
@@ -82,17 +82,12 @@ public static class GltfTextureEnumerator
///
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTexturesDistinct(GltfParser parser)
{
- var used = new HashSet();
- Func<(SubAssetKey, TextureImportParam), bool> add = (kv) =>
- {
- var (key, textureInfo) = kv;
- return used.Add(key);
- };
+ var usedTextures = new HashSet();
for (int i = 0; i < parser.GLTF.materials.Count; ++i)
{
- foreach (var kv in EnumerateTexturesForMaterial(parser, i))
+ foreach ((SubAssetKey key, TextureImportParam) kv in EnumerateTexturesReferencedByMaterials(parser, i))
{
- if (add(kv))
+ if (usedTextures.Add(kv.key))
{
yield return kv;
}
diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs
index f69ab93e4e..3df38300ce 100644
--- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs
+++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/GltfTextureImporter.cs
@@ -42,6 +42,18 @@ public static (SubAssetKey, TextureImportParam Param) CreateSRGB(GltfParser pars
var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.sRGB, default, default, getTextureBytesAsync, default, default, default, default, default);
return (key, param);
}
+
+ public static (SubAssetKey, TextureImportParam Param) CreateLinear(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
+ {
+ var gltfTexture = parser.GLTF.textures[textureIndex];
+ var gltfImage = parser.GLTF.images[gltfTexture.source];
+ var name = TextureImportName.GetUnityObjectName(TextureImportTypes.Linear, gltfTexture.name, gltfImage.uri);
+ var sampler = CreateSampler(parser.GLTF, textureIndex);
+ GetTextureBytesAsync getTextureBytesAsync = () => Task.FromResult(ToArray(parser.GLTF.GetImageBytesFromTextureIndex(parser.Storage, textureIndex)));
+ var key = new SubAssetKey(typeof(Texture2D), name);
+ var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, offset, scale, sampler, TextureImportTypes.Linear, default, default, getTextureBytesAsync, default, default, default, default, default);
+ return (key, param);
+ }
public static (SubAssetKey, TextureImportParam Param) CreateNormal(GltfParser parser, int textureIndex, Vector2 offset, Vector2 scale)
{
diff --git a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs
index 3b5eb1f65d..2ccb579e85 100644
--- a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs
+++ b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs
@@ -92,7 +92,7 @@ public void TextureExtractTest()
// extractor
var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), loader.TextureFactory.Textures.Select(x => (new SubAssetKey(typeof(Texture2D), x.Texture.name), x.Texture)).ToArray());
- var m = GltfTextureEnumerator.EnumerateTexturesForMaterial(parser, 0).FirstOrDefault(x => x.Item1.Name == "texture_1.standard");
+ var m = GltfTextureEnumerator.EnumerateTexturesReferencedByMaterials(parser, 0).FirstOrDefault(x => x.Item1.Name == "texture_1.standard");
Assert.Catch(() => extractor.Extract(m.Item1, m.Item2));
}
diff --git a/Assets/VRM/Runtime/IO/VRMMaterialImporter.cs b/Assets/VRM/Runtime/IO/VRMMaterialImporter.cs
index 107b63d0af..491793f190 100644
--- a/Assets/VRM/Runtime/IO/VRMMaterialImporter.cs
+++ b/Assets/VRM/Runtime/IO/VRMMaterialImporter.cs
@@ -134,7 +134,7 @@ public MaterialImportParam GetMaterialParam(GltfParser parser, int i)
else
{
// PBR or Unlit
- foreach (var (key, value) in GltfTextureEnumerator.EnumerateTexturesForMaterial(parser, i))
+ foreach (var (key, value) in GltfTextureEnumerator.EnumerateTexturesReferencedByMaterials(parser, i))
{
if (used.Add(key))
{
diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs
index 071f61e986..ca62fabc0c 100644
--- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs
+++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs
@@ -68,7 +68,7 @@ public override void OnInspectorGUI()
case Tabs.Materials:
if (m_parser != null)
{
- EditorMaterial.OnGUI(m_importer, m_parser, Vrm10MaterialImporter.EnumerateAllTexturesDistinct);
+ EditorMaterial.OnGUI(m_importer, m_parser, Vrm10TextureEnumerator.EnumerateAllTexturesDistinct);
}
break;
diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs
index 1a9bcbceba..833bf87338 100644
--- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs
+++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs
@@ -99,7 +99,7 @@ public static void Import(ScriptedImporter scriptedImporter, AssetImportContext
using (var loader = new Vrm10Importer(parser, externalObjectMap))
{
// settings TextureImporters
- foreach (var (key, textureInfo) in Vrm10MaterialImporter.EnumerateAllTexturesDistinct(parser))
+ foreach (var (key, textureInfo) in Vrm10TextureEnumerator.EnumerateAllTexturesDistinct(parser))
{
VRMShaders.TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalMap);
}
diff --git a/Assets/VRM10/Runtime/IO/Material.meta b/Assets/VRM10/Runtime/IO/Material.meta
new file mode 100644
index 0000000000..d27e009873
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Material.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 4c6dd47f5c9a46a9a3b26b40a28a52b3
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs
new file mode 100644
index 0000000000..9aba6f56ba
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs
@@ -0,0 +1,153 @@
+using System;
+using UniGLTF;
+using UniGLTF.Extensions.VRMC_materials_mtoon;
+using UnityEngine;
+using VRMShaders;
+
+namespace UniVRM10
+{
+ public static class Vrm10MToonMaterialImporter
+ {
+ public static bool TryGetBaseColorTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
+ {
+ try
+ {
+ pair = GltfPBRMaterial.BaseColorTexture(parser, src);
+ return true;
+ }
+ catch (NullReferenceException)
+ {
+ pair = default;
+ return false;
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ pair = default;
+ return false;
+ }
+ }
+
+ public static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair)
+ {
+ try
+ {
+ pair = GltfPBRMaterial.NormalTexture(parser, src);
+ return true;
+ }
+ catch (NullReferenceException)
+ {
+ pair = default;
+ return false;
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ pair = default;
+ return false;
+ }
+ }
+
+ public static bool TryGetShadeMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out pair);
+ }
+
+ public static bool TryGetShadingShiftTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
+ }
+
+ public static bool TryGetMatcapTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair);
+ }
+
+ public static bool TryGetRimMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair);
+ }
+
+ public static bool TryGetOutlineWidthMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair);
+ }
+
+ public static bool TryGetUvAnimationMaskTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair)
+ {
+ return TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair);
+ }
+
+ private static bool TryGetSRGBTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair)
+ {
+ try
+ {
+ var (offset, scale) = GetTextureOffsetAndScale(info);
+ pair = GltfTextureImporter.CreateSRGB(parser, info.index, offset, scale);
+ return true;
+ }
+ catch (NullReferenceException)
+ {
+ pair = default;
+ return false;
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ pair = default;
+ return false;
+ }
+ }
+ private static bool TryGetLinearTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair)
+ {
+ try
+ {
+ var (offset, scale) = GetTextureOffsetAndScale(info);
+ pair = GltfTextureImporter.CreateLinear(parser, info.index, offset, scale);
+ return true;
+ }
+ catch (NullReferenceException)
+ {
+ pair = default;
+ return false;
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ pair = default;
+ return false;
+ }
+ }
+
+ private static (Vector2, Vector2) GetTextureOffsetAndScale(Vrm10TextureInfo textureInfo)
+ {
+ if (glTF_KHR_texture_transform.TryGet(textureInfo, out var textureTransform))
+ {
+ return GltfMaterialImporter.GetTextureOffsetAndScale(textureTransform);
+ }
+ return (new Vector2(0, 0), new Vector2(1, 1));
+ }
+
+ ///
+ /// MToon 定義内の TextureInfo を glTFTextureInfo として扱う入れ物
+ ///
+ private sealed class Vrm10TextureInfo : glTFTextureInfo
+ {
+ public Vrm10TextureInfo(TextureInfo info)
+ {
+ if (info == null) return;
+
+ index = info.Index ?? -1;
+ texCoord = info.TexCoord ?? -1;
+ extensions = info.Extensions as glTFExtension;
+ extras = info.Extras as glTFExtension;
+ }
+
+ public Vrm10TextureInfo(ShadingShiftTextureInfo info)
+ {
+ if (info == null) return;
+
+ index = info.Index ?? -1;
+ texCoord = info.TexCoord ?? -1;
+ extensions = info.Extensions as glTFExtension;
+ extras = info.Extras as glTFExtension;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs.meta b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs.meta
new file mode 100644
index 0000000000..87b3016cad
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Material/Vrm10MToonMaterialImporter.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 1384da3bd22c4c4cb39c59d57b9c419a
+timeCreated: 1620387929
\ No newline at end of file
diff --git a/Assets/VRM10/Runtime/IO/Texture.meta b/Assets/VRM10/Runtime/IO/Texture.meta
new file mode 100644
index 0000000000..bd875b83ed
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Texture.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7fe27001b96146d3bbc53044ff91b536
+timeCreated: 1620374936
\ No newline at end of file
diff --git a/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs b/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs
new file mode 100644
index 0000000000..f2ba0ae2a7
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs
@@ -0,0 +1,111 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using UniGLTF;
+using UnityEngine;
+using VRMShaders;
+
+namespace UniVRM10
+{
+ public static class Vrm10TextureEnumerator
+ {
+ ///
+ /// glTF 全体で使うテクスチャーをユニークになるように列挙する
+ ///
+ public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTexturesDistinct(GltfParser parser)
+ {
+ if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
+ {
+ throw new System.Exception("not vrm");
+ }
+
+ var usedTextures = new HashSet();
+
+ // Thumbnail Texture referenced by VRM Meta.
+ if (TryGetMetaThumbnailTextureImportParam(parser, vrm, out (SubAssetKey key, TextureImportParam) thumbnail))
+ {
+ if (usedTextures.Add(thumbnail.key))
+ {
+ yield return thumbnail;
+ }
+ }
+
+ // Textures referenced by Materials.
+ for (int i = 0; i < parser.GLTF.materials.Count; ++i)
+ {
+ foreach ((SubAssetKey key, TextureImportParam) kv in EnumerateTexturesReferencedByMaterials(parser, i))
+ {
+ if (usedTextures.Add(kv.key))
+ {
+ yield return kv;
+ }
+ }
+ }
+ }
+
+ ///
+ /// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い)
+ ///
+ public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out (SubAssetKey, TextureImportParam) value)
+ {
+ if (vrm?.Meta?.ThumbnailImage == null)
+ {
+ value = default;
+ return false;
+ }
+
+ var imageIndex = vrm.Meta.ThumbnailImage.Value;
+ var gltfImage = parser.GLTF.images[imageIndex];
+ var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfImage.name, gltfImage.uri);
+
+ GetTextureBytesAsync getThumbnailImageBytesAsync = () =>
+ {
+ var bytes = parser.GLTF.GetImageBytes(parser.Storage, imageIndex);
+ return Task.FromResult(GltfTextureImporter.ToArray(bytes));
+ };
+ var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
+ getThumbnailImageBytesAsync, default, default,
+ default, default, default
+ );
+ var key = new SubAssetKey(typeof(Texture2D), name);
+ value = (key, param);
+ return true;
+ }
+
+ ///
+ /// Material によって参照されている Texture を Enumerate する.
+ /// まず VRM Material だと仮定して処理し, 失敗すれば glTF Material だとして処理する.
+ ///
+ public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateTexturesReferencedByMaterials(GltfParser parser, int i)
+ {
+ var m = parser.GLTF.materials[i];
+ if (UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(m.extensions, out var mToon))
+ {
+ // Enumerate VRM MToon Textures
+ if (Vrm10MToonMaterialImporter.TryGetBaseColorTexture(parser, m, out var litTex))
+ yield return litTex;
+ if (Vrm10MToonMaterialImporter.TryGetNormalTexture(parser, m, out var normalTex))
+ yield return normalTex;
+ if (Vrm10MToonMaterialImporter.TryGetShadeMultiplyTexture(parser, mToon, out var shadeTex))
+ yield return shadeTex;
+ if (Vrm10MToonMaterialImporter.TryGetShadingShiftTexture(parser, mToon, out var shadeShiftTex))
+ yield return shadeShiftTex;
+ if (Vrm10MToonMaterialImporter.TryGetMatcapTexture(parser, mToon, out var matcapTex))
+ yield return matcapTex;
+ if (Vrm10MToonMaterialImporter.TryGetRimMultiplyTexture(parser, mToon, out var rimTex))
+ yield return rimTex;
+ if (Vrm10MToonMaterialImporter.TryGetOutlineWidthMultiplyTexture(parser, mToon, out var outlineTex))
+ yield return outlineTex;
+ if (Vrm10MToonMaterialImporter.TryGetUvAnimationMaskTexture(parser, mToon, out var uvAnimMaskTex))
+ yield return uvAnimMaskTex;
+ }
+ else
+ {
+ // Fallback to glTF PBR & glTF Unlit
+ foreach (var kv in GltfTextureEnumerator.EnumerateTexturesReferencedByMaterials(parser, i))
+ {
+ yield return kv;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs.meta b/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs.meta
new file mode 100644
index 0000000000..aa9f50c2b4
--- /dev/null
+++ b/Assets/VRM10/Runtime/IO/Texture/Vrm10TextureEnumerator.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 7763318be4064ecba712dcc012dd1cb1
+timeCreated: 1620374912
\ No newline at end of file
diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs
index edd7cc3bdc..53768eaba8 100644
--- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs
+++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs
@@ -280,7 +280,7 @@ async Task LoadVrmAsync(IAwaitCaller awaitCaller, VRM10Controller controller, Un
{
m_meta.Authors.AddRange(src.Authors);
}
- if (Vrm10MaterialImporter.TryGetMetaThumbnailTextureImportParam(Parser, vrm, out (SubAssetKey, VRMShaders.TextureImportParam Param) kv))
+ if (Vrm10TextureEnumerator.TryGetMetaThumbnailTextureImportParam(Parser, vrm, out (SubAssetKey, VRMShaders.TextureImportParam Param) kv))
{
var texture = await TextureFactory.GetTextureAsync(kv.Param);
if (texture != null)
diff --git a/Assets/VRM10/Runtime/IO/Vrm10MaterialImporter.cs b/Assets/VRM10/Runtime/IO/Vrm10MaterialImporter.cs
index 3f42855c1f..605a81aa83 100644
--- a/Assets/VRM10/Runtime/IO/Vrm10MaterialImporter.cs
+++ b/Assets/VRM10/Runtime/IO/Vrm10MaterialImporter.cs
@@ -176,72 +176,5 @@ public static MaterialImportParam GetMaterialParam(GltfParser parser, int i)
}
return param;
}
-
- ///
- /// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い)
- ///
- /// MToonとは無関係だがとりあえずここに
- ///
- ///
- ///
- ///
- ///
- public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out (SubAssetKey, TextureImportParam) value)
- {
- if (vrm?.Meta == null || !vrm.Meta.ThumbnailImage.HasValue)
- {
- value = default;
- return false;
- }
-
- // thumbnail
- var imageIndex = vrm.Meta.ThumbnailImage.Value;
- var gltfImage = parser.GLTF.images[imageIndex];
- var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfImage.name, gltfImage.uri);
-
- GetTextureBytesAsync getBytesAsync = () =>
- {
- var bytes = parser.GLTF.GetImageBytes(parser.Storage, imageIndex);
- return Task.FromResult(GltfTextureImporter.ToArray(bytes));
- };
- var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
- getBytesAsync, default, default,
- default, default, default
- );
- var key = new SubAssetKey(typeof(Texture2D), name);
- value = (key, param);
- return true;
- }
-
- ///
- /// glTF 全体で使うテクスチャーをユニークになるように列挙する
- ///
- ///
- ///
- public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateAllTexturesDistinct(GltfParser parser)
- {
- if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
- {
- throw new System.Exception("not vrm");
- }
-
- if (TryGetMetaThumbnailTextureImportParam(parser, vrm, out (SubAssetKey, TextureImportParam) thumbnail))
- {
- yield return thumbnail;
- }
-
- var used = new HashSet();
- for (int i = 0; i < parser.GLTF.materials.Count; ++i)
- {
- var param = GetMaterialParam(parser, i);
- foreach (var (key, value) in param.EnumerateSubAssetKeyValue())
- {
- if (used.Add(key))
- {
- yield return (key, value);
- }
- }
- }
- }
}
}
diff --git a/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs b/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs
index ab20a575c6..b832730ca6 100644
--- a/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs
+++ b/Assets/VRMShaders/GLTF/IO/Editor/TextureImporterConfigurator.cs
@@ -95,6 +95,16 @@ public static void Configure(TextureImportParam textureInfo, IDictionary