From 1cf9cba349d045f4ba72f20ceb119775318e02a9 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 27 Jan 2021 15:12:46 +0900 Subject: [PATCH 1/3] Fix #694 Turkish "i" problem. --- Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs | 2 +- Assets/VRM/Tests/UniVRMSerializeTests.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs b/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs index 47e10a1df..7e078dd26 100644 --- a/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs +++ b/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs @@ -117,7 +117,7 @@ namespace VRM var group = new glTF_VRM_BlendShapeGroup { name = clip.BlendShapeName, - presetName = clip.Preset.ToString().ToLower(), + presetName = clip.Preset.ToString().ToLowerInvariant(), isBinary = clip.IsBinary, binds = list, materialValues = materialList, diff --git a/Assets/VRM/Tests/UniVRMSerializeTests.cs b/Assets/VRM/Tests/UniVRMSerializeTests.cs index 8809c6826..b266fa3b2 100644 --- a/Assets/VRM/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/Tests/UniVRMSerializeTests.cs @@ -190,6 +190,16 @@ namespace VRM var json = model.ToJson(); Assert.AreEqual(@"{""presetName"":""neutral"",""binds"":[],""materialValues"":[],""isBinary"":false}", json); Debug.Log(json); + + // https://github.com/vrm-c/UniVRM/issues/694 + // Must pass even if this computer's locale was tr-TR. + var model2 = new glTF_VRM_BlendShapeGroup() + { + presetName = "I", + }; + var json2 = model2.ToJson(); + Assert.AreEqual(@"{""presetName"":""i"",""binds"":[],""materialValues"":[],""isBinary"":false}", json2); + Debug.Log(json); } [Test] From 17023b94b21c624462f2a6880376a7875a92174e Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 27 Jan 2021 15:38:21 +0900 Subject: [PATCH 2/3] make BlendShapeClip serializer public. --- .../Runtime/Extensions/glTF_VRMExtensions.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs b/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs index 7e078dd26..65d4e7d18 100644 --- a/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs +++ b/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs @@ -19,6 +19,10 @@ namespace VRM public static glTF_VRM_BlendShapeBind Create(Transform root, BlendShapeBinding binding, gltfExporter exporter) { + if (root == null || exporter == null) + { + return null; + } if (string.IsNullOrEmpty((binding.RelativePath))) { Debug.LogWarning("binding.RelativePath is null"); @@ -77,19 +81,16 @@ namespace VRM }; } - /// - /// - /// - /// - /// - /// - /// - /// エクスポート中にBlendShapeIndexが変わったかもしれない public static void Add(this glTF_VRM_BlendShapeMaster master, BlendShapeClip clip, gltfExporter exporter) { - var list = new List(); - if (clip.Values != null) + master.blendShapeGroups.Add(clip.Serialize(exporter)); + } + + public static glTF_VRM_BlendShapeGroup Serialize(this BlendShapeClip clip, gltfExporter exporter) + { + var bindList = new List(); + if (clip.Values != null && exporter != null) { foreach (var value in clip.Values) { @@ -99,14 +100,14 @@ namespace VRM // Debug.LogFormat("{0}: skip blendshapebind", clip.name); continue; } - list.Add(bind); + bindList.Add(bind); } } - var materialList = new List(); + var materialValueBinds = new List(); if (clip.MaterialValues != null) { - materialList.AddRange(clip.MaterialValues.Select(y => new glTF_VRM_MaterialValueBind + materialValueBinds.AddRange(clip.MaterialValues.Select(y => new glTF_VRM_MaterialValueBind { materialName = y.MaterialName, propertyName = y.ValueName, @@ -114,15 +115,14 @@ namespace VRM })); } - var group = new glTF_VRM_BlendShapeGroup + return new glTF_VRM_BlendShapeGroup { name = clip.BlendShapeName, presetName = clip.Preset.ToString().ToLowerInvariant(), isBinary = clip.IsBinary, - binds = list, - materialValues = materialList, + binds = bindList, + materialValues = materialValueBinds, }; - master.blendShapeGroups.Add(group); } public static void Apply(this glTF_VRM_DegreeMap map, CurveMapper mapper) From 37b6d1ca04a0dd44076cbd405b0acfe477988c26 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 27 Jan 2021 15:41:50 +0900 Subject: [PATCH 3/3] The test checks the actual code. --- Assets/VRM/Tests/UniVRMSerializeTests.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Assets/VRM/Tests/UniVRMSerializeTests.cs b/Assets/VRM/Tests/UniVRMSerializeTests.cs index b266fa3b2..09de255ff 100644 --- a/Assets/VRM/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/Tests/UniVRMSerializeTests.cs @@ -190,16 +190,6 @@ namespace VRM var json = model.ToJson(); Assert.AreEqual(@"{""presetName"":""neutral"",""binds"":[],""materialValues"":[],""isBinary"":false}", json); Debug.Log(json); - - // https://github.com/vrm-c/UniVRM/issues/694 - // Must pass even if this computer's locale was tr-TR. - var model2 = new glTF_VRM_BlendShapeGroup() - { - presetName = "I", - }; - var json2 = model2.ToJson(); - Assert.AreEqual(@"{""presetName"":""i"",""binds"":[],""materialValues"":[],""isBinary"":false}", json2); - Debug.Log(json); } [Test] @@ -210,6 +200,19 @@ namespace VRM presetName = "aaaaaaaaaaaa_not_exists_", }; } + + [Test] + public void BlendShapePresetInvariantCultureTest() + { + // https://github.com/vrm-c/UniVRM/issues/694 + // Must pass even if this computer's locale was tr-TR. + var clip2 = ScriptableObject.CreateInstance(); + clip2.Preset = BlendShapePreset.I; + var model2 = clip2.Serialize(null); + var json2 = model2.ToJson(); + Assert.AreEqual(@"{""presetName"":""i"",""binds"":[],""materialValues"":[],""isBinary"":false}", json2); + Debug.Log(json2); + } [Test] public void DegreeMapTest()