From eff55a9465dbb397b83ed8f413b84981595869f9 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 30 Jul 2024 00:05:24 +0900 Subject: [PATCH] Fix Vrm10 Tests --- Assets/VRM10/Tests/ApiSampleTests.cs | 41 ++++------------------------ Assets/VRM10/Tests/MigrationTests.cs | 6 ++-- Assets/VRM10/Tests/TestAsset.cs | 5 +--- Assets/VRM10/Tests/TestVrm10.cs | 37 +++++++++++++++++++++++++ Assets/VRM10/Tests/TestVrm10.cs.meta | 3 ++ 5 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 Assets/VRM10/Tests/TestVrm10.cs create mode 100644 Assets/VRM10/Tests/TestVrm10.cs.meta diff --git a/Assets/VRM10/Tests/ApiSampleTests.cs b/Assets/VRM10/Tests/ApiSampleTests.cs index cc50aec15..3f9d1f58f 100644 --- a/Assets/VRM10/Tests/ApiSampleTests.cs +++ b/Assets/VRM10/Tests/ApiSampleTests.cs @@ -7,49 +7,20 @@ namespace UniVRM10.Test { public class ApiSampleTests { - VrmLib.Model ReadModel(string path) - { - var bytes = MigrationVrm.Migrate(File.ReadAllBytes(path)); - - var data = new GlbLowLevelParser(path, bytes).Parse(); - - var model = ModelReader.Read(data); - return model; - } - - GameObject BuildGameObject(Vrm10Data data, bool showMesh) - { - using (var loader = new Vrm10Importer(data, null)) - { - var loaded = loader.Load(); - if (showMesh) - { - loaded.ShowMeshes(); - } - loaded.EnableUpdateWhenOffscreen(); - return loaded.gameObject; - } - } - [Test] public void Sample() { var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm"; Debug.Log($"load: {path}"); - using (var data = new GlbFileParser(path).Parse()) - using (var migrated = Vrm10Data.Migrate(data, out Vrm10Data result, out MigrationData migration)) - { - Assert.NotNull(result); + var instance = TestVrm10.LoadPathAsBuiltInRP(path, canLoadVrm0X: true); + Assert.NotNull(instance); - var go = BuildGameObject(result, true); - Debug.Log(go); + var go = instance.gameObject; + Debug.Log(go); - // export - var vrmBytes = Vrm10Exporter.Export(go, textureSerializer: new EditorTextureSerializer()); - - Debug.Log($"export {vrmBytes.Length} bytes"); - } + var vrmBytes = TestVrm10.ExportAsBuiltInRP(go); + Debug.Log($"export {vrmBytes.Length} bytes"); } } } diff --git a/Assets/VRM10/Tests/MigrationTests.cs b/Assets/VRM10/Tests/MigrationTests.cs index 09add1b02..999584449 100644 --- a/Assets/VRM10/Tests/MigrationTests.cs +++ b/Assets/VRM10/Tests/MigrationTests.cs @@ -197,7 +197,7 @@ namespace UniVRM10 { try { - Vrm10.LoadPathAsync(gltf.FullName, true, controlRigGenerationOption: ControlRigGenerationOption.None).Wait(); + TestVrm10.LoadPathAsBuiltInRP(gltf.FullName); } catch (UnNormalizedException) { @@ -372,7 +372,7 @@ namespace UniVRM10 new Color(2.0f, 2.0f, 2.0f, 1), }; - var instance106 = Vrm10.LoadBytesAsync(model106, awaitCaller: new ImmediateCaller()).Result; + var instance106 = TestVrm10.LoadBytesAsBuiltInRP(model106); var materials106 = instance106.GetComponent().Materials; Assert.AreEqual(materialCount, materials106.Count); for (var idx = 0; idx < materialCount; ++idx) @@ -384,7 +384,7 @@ namespace UniVRM10 if (correctEmissions[idx].HasValue) AssertAreApproximatelyEqualColor(correctEmissions[idx].Value, material.GetColor(emissionName)); } - var instance107 = Vrm10.LoadBytesAsync(model107, awaitCaller: new ImmediateCaller()).Result; + var instance107 = TestVrm10.LoadBytesAsBuiltInRP(model107); var materials107 = instance107.GetComponent().Materials; Assert.AreEqual(materialCount, materials107.Count); for (var idx = 0; idx < materialCount; ++idx) diff --git a/Assets/VRM10/Tests/TestAsset.cs b/Assets/VRM10/Tests/TestAsset.cs index 6077c2c44..5982583ee 100644 --- a/Assets/VRM10/Tests/TestAsset.cs +++ b/Assets/VRM10/Tests/TestAsset.cs @@ -16,10 +16,7 @@ namespace UniVRM10 public static Vrm10Instance LoadAlicia() { - var task = Vrm10.LoadPathAsync(AliciaPath, canLoadVrm0X: true); - task.Wait(); - var instance = task.Result; - + var instance = TestVrm10.LoadPathAsBuiltInRP(AliciaPath, canLoadVrm0X: true); return instance.GetComponent(); } } diff --git a/Assets/VRM10/Tests/TestVrm10.cs b/Assets/VRM10/Tests/TestVrm10.cs new file mode 100644 index 000000000..108c6d321 --- /dev/null +++ b/Assets/VRM10/Tests/TestVrm10.cs @@ -0,0 +1,37 @@ +using UniGLTF; +using UnityEngine; + +namespace UniVRM10 +{ + public static class TestVrm10 + { + public static Vrm10Instance LoadBytesAsBuiltInRP(byte[] bytes, bool canLoadVrm0X = true) + { + return Vrm10.LoadBytesAsync( + bytes, + canLoadVrm0X: canLoadVrm0X, + awaitCaller: new ImmediateCaller(), + materialGenerator: new BuiltInVrm10MaterialDescriptorGenerator() + ).Result; + } + + public static Vrm10Instance LoadPathAsBuiltInRP(string path, bool canLoadVrm0X = true) + { + return Vrm10.LoadPathAsync( + path, + canLoadVrm0X: canLoadVrm0X, + awaitCaller: new ImmediateCaller(), + materialGenerator: new BuiltInVrm10MaterialDescriptorGenerator() + ).Result; + } + + public static byte[] ExportAsBuiltInRP(GameObject gameObject) + { + return Vrm10Exporter.Export( + gameObject, + materialExporter: new BuiltInVrm10MaterialExporter(), + textureSerializer: new EditorTextureSerializer() + ); + } + } +} \ No newline at end of file diff --git a/Assets/VRM10/Tests/TestVrm10.cs.meta b/Assets/VRM10/Tests/TestVrm10.cs.meta new file mode 100644 index 000000000..69837185f --- /dev/null +++ b/Assets/VRM10/Tests/TestVrm10.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4c9e0897ac194db3b7a55132871e6d75 +timeCreated: 1722265007 \ No newline at end of file