diff --git a/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs b/Assets/VRM/Runtime/Extensions/glTF_VRMExtensions.cs index 47e10a1df..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().ToLower(), + 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) diff --git a/Assets/VRM/Tests/UniVRMSerializeTests.cs b/Assets/VRM/Tests/UniVRMSerializeTests.cs index 8809c6826..09de255ff 100644 --- a/Assets/VRM/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/Tests/UniVRMSerializeTests.cs @@ -200,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()