Testを追加

This commit is contained in:
ousttrue 2021-04-16 12:49:56 +09:00
parent 98a3ad27dc
commit 36bba50914
7 changed files with 87 additions and 21 deletions

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
using UnityEngine;
using VRMShaders;
namespace UniGLTF
{
public static class MaterialImporterParamExtensions
{
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateSubAssetKeyValue(this MaterialImportParam param)
{
foreach (var kv in param.TextureSlots)
{
var key = new SubAssetKey(typeof(Texture2D), kv.Key);
yield return (key, kv.Value);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95bb02953e0720c45a848856c1006ed4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,5 +31,10 @@ namespace UniGLTF
Type = t;
Name = name;
}
public override string ToString()
{
return $"{Type}:{Name}";
}
}
}

View File

@ -177,13 +177,7 @@ namespace UniVRM10
return true;
}
/// <summary>
/// Material一つ分のテクスチャーを列挙する。重複する場合がある
/// </summary>
/// <param name="parser"></param>
/// <param name="m"></param>
/// <returns></returns>
public static IEnumerable<(SubAssetKey, TextureImportParam)> EnumerateTexturesForMaterial(GltfParser parser, int i)
public static MaterialImportParam GetMaterialImportParam(GltfParser parser, int i)
{
// mtoon
if (!TryCreateParam(parser, i, out MaterialImportParam param))
@ -195,12 +189,7 @@ namespace UniVRM10
GltfPBRMaterial.TryCreateParam(parser, i, out param);
}
}
foreach (var kv in param.TextureSlots)
{
var key = new SubAssetKey(typeof(Texture2D), kv.Key);
yield return (key, kv.Value);
}
return param;
}
/// <summary>
@ -257,18 +246,14 @@ namespace UniVRM10
}
var used = new HashSet<SubAssetKey>();
Func<(SubAssetKey, TextureImportParam), bool> add = (kv) =>
{
var (key, textureInfo) = kv;
return used.Add(key);
};
for (int i = 0; i < parser.GLTF.materials.Count; ++i)
{
foreach (var kv in EnumerateTexturesForMaterial(parser, i))
var param = GetMaterialImportParam(parser, i);
foreach (var (key, value) in param.EnumerateSubAssetKeyValue())
{
if (add(kv))
if (used.Add(key))
{
yield return kv;
yield return (key, value);
}
}
}

View File

@ -0,0 +1,35 @@
using System.IO;
using System.Linq;
using NUnit.Framework;
using UniGLTF;
using UnityEngine;
namespace UniVRM10
{
public class MaterialImporterTests
{
static string AliciaPath
{
get
{
return Path.GetFullPath(Application.dataPath + "/../Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm")
.Replace("\\", "/");
}
}
[Test]
public void MaterialImporterTest()
{
var migratedBytes = MigrationVrm.Migrate(File.ReadAllBytes(AliciaPath));
var parser = new GltfParser();
parser.Parse(AliciaPath, migratedBytes);
var materialParam = Vrm10MaterialImporter.GetMaterialImportParam(parser, 0);
Assert.AreEqual("VRM/MToon", materialParam.ShaderName);
Assert.AreEqual("Alicia_body", materialParam.TextureSlots["_MainTex"].UnityObjectName);
var (key, value) = materialParam.EnumerateSubAssetKeyValue().First();
Assert.AreEqual(new SubAssetKey(typeof(Texture2D), "Alicia_body"), key);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9609b7e054ece274bbe4a2e1a3405373
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,6 +4,7 @@
"VrmLib",
"VRM10",
"UniGLTF",
"VRMShaders.GLTF.IO.Runtime",
"VRMShaders.GLTF.IO.Editor"
],
"optionalUnityReferences": [