From 3f7fa08f0a518c6d97008d9d652cd69397571634 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 19 May 2021 16:01:26 +0900 Subject: [PATCH 1/2] add test --- Assets/VRM/Tests/VRMLookAtTests.cs | 77 ++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/Assets/VRM/Tests/VRMLookAtTests.cs b/Assets/VRM/Tests/VRMLookAtTests.cs index fe01e118e..702d1bf1d 100644 --- a/Assets/VRM/Tests/VRMLookAtTests.cs +++ b/Assets/VRM/Tests/VRMLookAtTests.cs @@ -31,7 +31,7 @@ namespace VRM var go = loader.Root; var fp = go.GetComponent(); GameObject.DestroyImmediate(go.GetComponent()); - go.AddComponent(); + var lookAt = go.AddComponent(); bytes = VRMEditorExporter.Export(go, null, new VRMExportSettings { PoseFreeze = true, @@ -40,9 +40,80 @@ namespace VRM var parser2 = new GltfParser(); parser2.Parse(AliciaPath, bytes); - var loader2 = new VRMImporterContext(parser2); + using (var loader2 = new VRMImporterContext(parser2)) + { + Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType); + } + } - Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType); + [Test] + public void VRMLookAtCurveMapWithFreezeTest() + { + var parser = new GltfParser(); + parser.ParsePath(AliciaPath); + byte[] bytes = default; + CurveMapper horizontalInner = default; + using (var loader = new VRMImporterContext(parser)) + { + loader.Load(); + loader.ShowMeshes(); + + var go = loader.Root; + var fp = go.GetComponent(); + var lookAt = go.GetComponent(); + horizontalInner = lookAt.HorizontalInner; + bytes = VRMEditorExporter.Export(go, null, new VRMExportSettings + { + PoseFreeze = true, + }); + } + + var parser2 = new GltfParser(); + parser2.Parse(AliciaPath, bytes); + using (var loader = new VRMImporterContext(parser2)) + { + loader.Load(); + loader.ShowMeshes(); + + var lookAt = loader.Root.GetComponent(); + Assert.AreEqual(horizontalInner.CurveXRangeDegree, lookAt.HorizontalInner.CurveXRangeDegree); + Assert.AreEqual(horizontalInner.CurveYRangeDegree, lookAt.HorizontalInner.CurveYRangeDegree); + } + } + + [Test] + public void VRMLookAtCurveMapTest() + { + var parser = new GltfParser(); + parser.ParsePath(AliciaPath); + byte[] bytes = default; + CurveMapper horizontalInner = default; + using (var loader = new VRMImporterContext(parser)) + { + loader.Load(); + loader.ShowMeshes(); + + var go = loader.Root; + var fp = go.GetComponent(); + var lookAt = go.GetComponent(); + horizontalInner = lookAt.HorizontalInner; + bytes = VRMEditorExporter.Export(go, null, new VRMExportSettings + { + PoseFreeze = false, + }); + } + + var parser2 = new GltfParser(); + parser2.Parse(AliciaPath, bytes); + using (var loader = new VRMImporterContext(parser2)) + { + loader.Load(); + loader.ShowMeshes(); + + var lookAt = loader.Root.GetComponent(); + Assert.AreEqual(horizontalInner.CurveXRangeDegree, lookAt.HorizontalInner.CurveXRangeDegree); + Assert.AreEqual(horizontalInner.CurveYRangeDegree, lookAt.HorizontalInner.CurveYRangeDegree); + } } } } From b8223a20c3928242a9c64fd2d8ce4269fe31adf4 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 19 May 2021 16:04:16 +0900 Subject: [PATCH 2/2] export with bone normalize cause, drop look at curve params --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 24 ++++++++++++++++++- .../SkinnedMeshUtility/VRMBoneNormalizer.cs | 7 ++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index cbc750d2a..c18d2c3bb 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -7,7 +7,7 @@ using UnityEngine; namespace VRM { [Serializable] - public class CurveMapper + public class CurveMapper : IEquatable { public AnimationCurve Curve = AnimationCurve.Linear(0, 0, 1.0f, 1.0f); @@ -37,6 +37,12 @@ namespace VRM } } + public void Assign(CurveMapper mapper) + { + CurveXRangeDegree = mapper.CurveXRangeDegree; + CurveYRangeDegree = mapper.CurveYRangeDegree; + } + public void Apply(glTF_VRM_DegreeMap degreeMap) { CurveXRangeDegree = degreeMap.xRange; @@ -71,5 +77,21 @@ namespace VRM } return Curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; } + + public bool Equals(CurveMapper other) + { + if (CurveXRangeDegree != other.CurveXRangeDegree) return false; + if (CurveYRangeDegree != other.CurveYRangeDegree) return false; + return true; + } + + public override bool Equals(object obj) + { + if (obj is CurveMapper mapper) + { + return Equals(mapper); + } + return base.Equals(obj); + } } } diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs index 65b2a6b7a..3b5891824 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs @@ -228,6 +228,10 @@ namespace VRM if (src != null) { var dst = root.AddComponent(); + dst.HorizontalInner.Assign(src.HorizontalInner); + dst.HorizontalOuter.Assign(src.HorizontalOuter); + dst.VerticalUp.Assign(src.VerticalUp); + dst.VerticalDown.Assign(src.VerticalDown); } } { @@ -236,6 +240,9 @@ namespace VRM if (src != null) { var dst = root.AddComponent(); + dst.Horizontal.Assign(src.Horizontal); + dst.VerticalUp.Assign(src.VerticalUp); + dst.VerticalDown.Assign(src.VerticalDown); } }