mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-04 08:52:22 -05:00
Testを追加
This commit is contained in:
parent
98a3ad27dc
commit
36bba50914
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95bb02953e0720c45a848856c1006ed4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -31,5 +31,10 @@ namespace UniGLTF
|
|||
Type = t;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Type}:{Name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
Assets/VRM10/Tests/MaterialImportTests.cs
Normal file
35
Assets/VRM10/Tests/MaterialImportTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Tests/MaterialImportTests.cs.meta
Normal file
11
Assets/VRM10/Tests/MaterialImportTests.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9609b7e054ece274bbe4a2e1a3405373
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
"VrmLib",
|
||||
"VRM10",
|
||||
"UniGLTF",
|
||||
"VRMShaders.GLTF.IO.Runtime",
|
||||
"VRMShaders.GLTF.IO.Editor"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user