From 1d0b485b02ed4d6c0de0f761acc8af653eb4b577 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 19:23:56 +0900 Subject: [PATCH 01/10] rename material --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs index c53a9c105..3f706f4e0 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs @@ -275,11 +275,17 @@ namespace UniGLTF public void FixMaterialNameUnique() { var used = new HashSet(); - foreach (var material in GLTF.materials) + for (int i = 0; i < GLTF.materials.Count; ++i) { + var material = GLTF.materials[i]; var originalName = material.name; int j = 2; + if (string.IsNullOrEmpty(material.name)) + { + material.name = $"material_{i}"; + } + while (true) { if (used.Add(material.name)) From b34afd81d56ed5a73411379897c5fa68001c7905 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 19:29:23 +0900 Subject: [PATCH 02/10] fix image.uri startsWith "data:" --- .../Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs | 2 +- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs index 6babf8bb1..76a4ad9e6 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterImpl.cs @@ -83,7 +83,7 @@ namespace UniGLTF { var gltfTexture = parser.GLTF.textures.First(y => y.name == texParam.GltflName); var gltfImage = parser.GLTF.images[gltfTexture.source]; - if (!string.IsNullOrEmpty(gltfImage.uri)) + if (!string.IsNullOrEmpty(gltfImage.uri) && !gltfImage.uri.StartsWith("data:")) { var child = dir.Child(gltfImage.uri); var asset = AssetDatabase.LoadAssetAtPath(child.Value); diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs index 3f706f4e0..d0823568e 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs @@ -230,9 +230,9 @@ namespace UniGLTF { var gltfTexture = GLTF.textures[i]; var gltfImage = GLTF.images[gltfTexture.source]; - if (!string.IsNullOrEmpty(gltfImage.uri)) + if (!string.IsNullOrEmpty(gltfImage.uri) && !gltfImage.uri.StartsWith("data:")) { - // from image uri + // from image uri gltfTexture.name = Path.GetFileNameWithoutExtension(gltfImage.uri); } if (string.IsNullOrEmpty(gltfTexture.name)) From bf4fca66c06110eaf6eeca0880281d01afdfcff5 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 19:38:36 +0900 Subject: [PATCH 03/10] occlusion only --- .../IO/TextureIO/OcclusionMetallicRoughnessConverter.cs | 6 +++++- .../UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/OcclusionMetallicRoughnessConverter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/OcclusionMetallicRoughnessConverter.cs index 72ad2d1af..514ed6067 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/OcclusionMetallicRoughnessConverter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/OcclusionMetallicRoughnessConverter.cs @@ -69,7 +69,11 @@ namespace UniGLTF } else if (occlusionTexture != null) { - throw new NotImplementedException("occlusion only"); + var copyTexture = TextureConverter.CopyTexture(occlusionTexture, glTFTextureTypes.OcclusionMetallicRoughness, null); + copyTexture.SetPixels32(copyTexture.GetPixels32().Select(x => ImportPixel(default, metallicFactor, roughnessFactor, x)).ToArray()); + copyTexture.Apply(); + copyTexture.name = occlusionTexture.name; + return copyTexture; } else { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs index 70872c48c..24f999f5b 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs @@ -178,7 +178,11 @@ namespace UniGLTF case GetTextureParam.TextureTypes.StandardMap: { - var baseTexture = await GetOrCreateBaseTexture(awaitCaller, gltf, param.Index0.Value, false); + TextureLoadInfo baseTexture = default; + if (param.Index0.HasValue) + { + baseTexture = await GetOrCreateBaseTexture(awaitCaller, gltf, param.Index0.Value, false); + } TextureLoadInfo occlusionBaseTexture = default; if (param.Index1.HasValue) { From 67b083b10fa165f5ff27dadab4cb549ad6227117 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 19:59:45 +0900 Subject: [PATCH 04/10] add LoadTests https://github.com/KhronosGroup/glTF-Sample-Models --- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 85 +++++++++++++++++++ .../UniGLTF/Tests/UniGLTF/LoadTests.cs.meta | 11 +++ 2 files changed, 96 insertions(+) create mode 100644 Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs create mode 100644 Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs new file mode 100644 index 000000000..088336b43 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.IO; +using NUnit.Framework; +using UnityEngine; + +namespace UniGLTF +{ + public class LoadTests + { + static IEnumerable EnumerateGltfFiles(DirectoryInfo dir) + { + if (dir.Name == ".git") + { + yield break; + } + + foreach (var child in dir.EnumerateDirectories()) + { + foreach (var x in EnumerateGltfFiles(child)) + { + yield return x; + } + } + + foreach (var child in dir.EnumerateFiles()) + { + switch (child.Extension.ToLower()) + { + case ".gltf": + case ".glb": + yield return child; + break; + } + } + } + + static void Load(FileInfo gltf) + { + var parser = new GltfParser(); + try + { + parser.ParsePath(gltf.FullName); + } + catch (Exception) + { + Debug.LogError($"ParseError: {gltf}"); + throw; + } + + try + { + using (var importer = new ImporterContext(parser)) + { + importer.Load(); + } + } + catch (Exception) + { + Debug.LogError($"LoadError: {gltf}"); + throw; + } + } + + [Test] + public void GltfSampleModelsTests() + { + var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS"); + if (string.IsNullOrEmpty(env)) + { + return; + } + var root = new DirectoryInfo(env); + if (!root.Exists) + { + return; + } + + foreach (var gltf in EnumerateGltfFiles(root)) + { + Load(gltf); + } + } + } +} diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta new file mode 100644 index 000000000..956ec4ff5 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0454ecef7a44cf4280a6f0fcacf3666 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4187014b943d5b068b2848b483186dd7fc07fb9c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:17:51 +0900 Subject: [PATCH 05/10] log --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs | 9 ++++++--- Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs | 6 +++--- .../Runtime/UniGLTF/IO/ImporterContextExtensions.cs | 2 +- .../Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs | 2 +- .../Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs index d0823568e..770b6709f 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfParser.cs @@ -77,6 +77,8 @@ namespace UniGLTF Parse(path, File.ReadAllBytes(path)); } + public string TargetPath; + /// /// Parse gltf json or Parse json chunk of glb /// @@ -84,6 +86,7 @@ namespace UniGLTF /// public virtual void Parse(string path, Byte[] bytes) { + TargetPath = path; var ext = Path.GetExtension(path).ToLower(); switch (ext) { @@ -185,7 +188,7 @@ namespace UniGLTF { // empty mesh.name = "mesh_" + Guid.NewGuid().ToString("N"); - Debug.LogWarning($"no name: => {mesh.name}"); + // Debug.LogWarning($"mesh.name: => {mesh.name}"); used.Add(mesh.name); } else @@ -195,7 +198,7 @@ namespace UniGLTF { // rename var uname = lower + "_" + Guid.NewGuid().ToString("N"); - Debug.LogWarning($"same name: {lower} => {uname}"); + // Debug.LogWarning($"mesh.name: {lower} => {uname}"); mesh.name = uname; lower = uname; } @@ -261,7 +264,7 @@ namespace UniGLTF { // rename var uname = lower + "_" + Guid.NewGuid().ToString("N"); - Debug.LogWarning($"texture.name: {lower} => {uname}"); + // Debug.LogWarning($"texture.name: {lower} => {uname}"); gltfTexture.name = uname; if (!used.Add(uname)) { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 503d77127..634f7cfdb 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -247,7 +247,7 @@ namespace UniGLTF foreach (var x in AnimationClips) { #if VRM_DEVELOP - Debug.Log($"Destroy {x}"); + // Debug.Log($"Destroy {x}"); #endif destroy(x); } @@ -256,7 +256,7 @@ namespace UniGLTF foreach (var x in Meshes) { #if VRM_DEVELOP - Debug.Log($"Destroy {x.Mesh}"); + // Debug.Log($"Destroy {x.Mesh}"); #endif destroy(x.Mesh); } @@ -268,7 +268,7 @@ namespace UniGLTF if (m_ownRoot && Root != null) { #if VRM_DEVELOP - Debug.Log($"Destroy {Root}"); + // Debug.Log($"Destroy {Root}"); #endif destroy(Root); } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs index b975dbfbd..4cc1e306d 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs @@ -29,7 +29,7 @@ namespace UniGLTF } #if VRM_DEVELOP - Debug.Log(meassureTime.GetSpeedLog()); + Debug.Log($"{self.Parser.TargetPath}: {meassureTime.GetSpeedLog()}"); #endif } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs index b36126eba..0aa88ea9e 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs @@ -93,7 +93,7 @@ namespace UniGLTF { // 外部の '.asset' からロードしていない #if VRM_DEVELOP - Debug.Log($"Destroy {x.Asset}"); + // Debug.Log($"Destroy {x.Asset}"); #endif UnityEngine.Object.DestroyImmediate(x.Asset, false); } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs index 24f999f5b..bbae20e97 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureFactory.cs @@ -95,7 +95,7 @@ namespace UniGLTF if (!kv.Value.IsExternal) { #if VRM_DEVELOP - Debug.Log($"Destroy {kv.Value.Texture}"); + // Debug.Log($"Destroy {kv.Value.Texture}"); #endif destroy(kv.Value.Texture); } From 5e935ba6a6dfa205ad0681a068e37d00993ba3e5 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:18:05 +0900 Subject: [PATCH 06/10] skip draco --- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs index 088336b43..d68067a1a 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -42,10 +42,10 @@ namespace UniGLTF { parser.ParsePath(gltf.FullName); } - catch (Exception) + catch (Exception ex) { Debug.LogError($"ParseError: {gltf}"); - throw; + Debug.LogException(ex); } try @@ -55,10 +55,14 @@ namespace UniGLTF importer.Load(); } } - catch (Exception) + catch (UniGLTFNotSupportedException) + { + // skip + } + catch (Exception ex) { Debug.LogError($"LoadError: {gltf}"); - throw; + Debug.LogException(ex); } } @@ -70,7 +74,7 @@ namespace UniGLTF { return; } - var root = new DirectoryInfo(env); + var root = new DirectoryInfo($"{env}/2.0"); if (!root.Exists) { return; From cc784f93f8d2bcf7c098db6b8399bf1889c8f1b0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:49:58 +0900 Subject: [PATCH 07/10] GetTangentMode --- Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs index a5d9d65a0..dc561cbcf 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/AnimationImporterUtil.cs @@ -16,7 +16,7 @@ namespace UniGLTF private static TangentMode GetTangentMode(string interpolation) { - if (interpolation == glTFAnimationTarget.Interpolations.LINEAR.ToString()) + if (string.IsNullOrEmpty(interpolation) || interpolation == glTFAnimationTarget.Interpolations.LINEAR.ToString()) { return TangentMode.Linear; } @@ -30,7 +30,7 @@ namespace UniGLTF } else { - throw new NotImplementedException(); + throw new UniGLTFNotSupportedException($"unknown interpolation: {interpolation}"); } } @@ -274,7 +274,7 @@ namespace UniGLTF if (!gltf_mesh_extras_targetNames.TryGet(mesh, out List targetNames)) { - throw new Exception("glTF BlendShape Animation. targetNames invalid."); + throw new UniGLTFNotSupportedException("glTF BlendShape Animation. targetNames invalid."); } var keyNames = targetNames From 6a60ab3ce72977bcc8a5eb26e919109fef054d3d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:50:05 +0900 Subject: [PATCH 08/10] error handling --- .../UniGLTF/IO/ImporterContextExtensions.cs | 9 +----- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs index 4cc1e306d..900440fe3 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs @@ -18,14 +18,7 @@ namespace UniGLTF } if (task.IsFaulted) { - if (task.Exception is AggregateException ae && ae.InnerExceptions.Count == 1) - { - throw ae.InnerException; - } - else - { - throw task.Exception; - } + throw new AggregateException(task.Exception); } #if VRM_DEVELOP diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs index d68067a1a..acab2b4fb 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -35,7 +35,25 @@ namespace UniGLTF } } - static void Load(FileInfo gltf) + static void Message(string path, Exception exception) + { + while (exception.InnerException != null) + { + exception = exception.InnerException; + } + + if (exception is UniGLTFNotSupportedException ex) + { + // skip + Debug.LogWarning($"LoadError: {path}: {ex}"); + } + else + { + Debug.LogError($"LoadError: {path}: {exception}"); + } + } + + static void Load(FileInfo gltf, DirectoryInfo root) { var parser = new GltfParser(); try @@ -55,14 +73,9 @@ namespace UniGLTF importer.Load(); } } - catch (UniGLTFNotSupportedException) - { - // skip - } catch (Exception ex) { - Debug.LogError($"LoadError: {gltf}"); - Debug.LogException(ex); + Message(gltf.FullName.Substring(root.FullName.Length), ex); } } @@ -82,7 +95,7 @@ namespace UniGLTF foreach (var gltf in EnumerateGltfFiles(root)) { - Load(gltf); + Load(gltf, root); } } } From 1f9f5e74989d6a5967efc8053e0a310ebcaafe2b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:52:17 +0900 Subject: [PATCH 09/10] exception --- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs index acab2b4fb..d479880e1 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -44,12 +44,12 @@ namespace UniGLTF if (exception is UniGLTFNotSupportedException ex) { - // skip Debug.LogWarning($"LoadError: {path}: {ex}"); } else { - Debug.LogError($"LoadError: {path}: {exception}"); + Debug.LogError($"LoadError: {path}"); + Debug.LogException(exception); } } From 199bc3e170f395ef87c0f79bab9ce165f898d227 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:58:46 +0900 Subject: [PATCH 10/10] add VRM_TEST_MODELS --- .../{LoadTests.cs => GltfLoadTests.cs} | 2 +- ...oadTests.cs.meta => GltfLoadTests.cs.meta} | 0 Assets/VRM/Tests/Exception.cs | 0 Assets/VRM/Tests/Exception.cs.meta | 11 +++ Assets/VRM/Tests/VRMLoadTests.cs | 97 +++++++++++++++++++ Assets/VRM/Tests/VRMLoadTests.cs.meta | 11 +++ 6 files changed, 120 insertions(+), 1 deletion(-) rename Assets/UniGLTF/Tests/UniGLTF/{LoadTests.cs => GltfLoadTests.cs} (98%) rename Assets/UniGLTF/Tests/UniGLTF/{LoadTests.cs.meta => GltfLoadTests.cs.meta} (100%) create mode 100644 Assets/VRM/Tests/Exception.cs create mode 100644 Assets/VRM/Tests/Exception.cs.meta create mode 100644 Assets/VRM/Tests/VRMLoadTests.cs create mode 100644 Assets/VRM/Tests/VRMLoadTests.cs.meta diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs similarity index 98% rename from Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs rename to Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs index d479880e1..2f60da547 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace UniGLTF { - public class LoadTests + public class GltfLoadTests { static IEnumerable EnumerateGltfFiles(DirectoryInfo dir) { diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta b/Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs.meta similarity index 100% rename from Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta rename to Assets/UniGLTF/Tests/UniGLTF/GltfLoadTests.cs.meta diff --git a/Assets/VRM/Tests/Exception.cs b/Assets/VRM/Tests/Exception.cs new file mode 100644 index 000000000..e69de29bb diff --git a/Assets/VRM/Tests/Exception.cs.meta b/Assets/VRM/Tests/Exception.cs.meta new file mode 100644 index 000000000..4706c3120 --- /dev/null +++ b/Assets/VRM/Tests/Exception.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bd80effebd71ba445976e6285b714f1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/Tests/VRMLoadTests.cs b/Assets/VRM/Tests/VRMLoadTests.cs new file mode 100644 index 000000000..d671ca3ec --- /dev/null +++ b/Assets/VRM/Tests/VRMLoadTests.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.IO; +using NUnit.Framework; +using UniGLTF; +using UnityEngine; + +namespace VRM +{ + public class VRMLoadTest + { + static IEnumerable EnumerateGltfFiles(DirectoryInfo dir) + { + if (dir.Name == ".git") + { + yield break; + } + + foreach (var child in dir.EnumerateDirectories()) + { + foreach (var x in EnumerateGltfFiles(child)) + { + yield return x; + } + } + + foreach (var child in dir.EnumerateFiles()) + { + switch (child.Extension.ToLower()) + { + case ".vrm": + yield return child; + break; + } + } + } + + static void Message(string path, Exception exception) + { + while (exception.InnerException != null) + { + exception = exception.InnerException; + } + + { + Debug.LogError($"LoadError: {path}"); + Debug.LogException(exception); + } + } + + static void Load(FileInfo gltf, DirectoryInfo root) + { + var parser = new GltfParser(); + try + { + parser.ParsePath(gltf.FullName); + } + catch (Exception ex) + { + Debug.LogError($"ParseError: {gltf}"); + Debug.LogException(ex); + } + + try + { + using (var importer = new VRMImporterContext(parser)) + { + importer.Load(); + } + } + catch (Exception ex) + { + Message(gltf.FullName.Substring(root.FullName.Length), ex); + } + } + + [Test] + public void VrmTestModelsTests() + { + var env = System.Environment.GetEnvironmentVariable("VRM_TEST_MODELS"); + if (string.IsNullOrEmpty(env)) + { + return; + } + var root = new DirectoryInfo(env); + if (!root.Exists) + { + return; + } + + foreach (var gltf in EnumerateGltfFiles(root)) + { + Load(gltf, root); + } + } + } +} diff --git a/Assets/VRM/Tests/VRMLoadTests.cs.meta b/Assets/VRM/Tests/VRMLoadTests.cs.meta new file mode 100644 index 000000000..ccea1448f --- /dev/null +++ b/Assets/VRM/Tests/VRMLoadTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f4a4042cfb50bb84495fd90f548683ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: