From 668b97d25543849e38b42298ed9dcfa8ed529944 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 30 May 2022 22:02:12 +0900 Subject: [PATCH 1/2] Update JsonSchema and regenerate serializer. --- Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs | 5 +++++ Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs | 3 +++ Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs | 5 +++++ vrm-specification | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs index 2d6a275c0..4861c58fc 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Deserializer.g.cs @@ -323,6 +323,11 @@ public static Spring Deserialize_Springs_ITEM(JsonNode parsed) continue; } + if(key=="center"){ + value.Center = kv.Value.GetInt32(); + continue; + } + } return value; } diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs index 84e625e8d..17bf58678 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Format.g.cs @@ -112,6 +112,9 @@ namespace UniGLTF.Extensions.VRMC_springBone // Indices of ColliderGroups that detect collision with this spring. public int[] ColliderGroups; + + // An index of node which is used as a root of center space. + public int? Center; } public class VRMC_springBone diff --git a/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs b/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs index fde014c66..434dd2c33 100644 --- a/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs +++ b/Assets/VRM10/Runtime/Format/SpringBone/Serializer.g.cs @@ -305,6 +305,11 @@ public static void Serialize_Springs_ITEM(JsonFormatter f, Spring value) __springs_ITEM_Serialize_ColliderGroups(f, value.ColliderGroups); } + if(value.Center.HasValue){ + f.Key("center"); + f.Value(value.Center.GetValueOrDefault()); + } + f.EndMap(); } diff --git a/vrm-specification b/vrm-specification index 741b0c3f3..729461b5c 160000 --- a/vrm-specification +++ b/vrm-specification @@ -1 +1 @@ -Subproject commit 741b0c3f3cb44111d9e9ea179de9e3fc545ac50a +Subproject commit 729461b5c0e22bf74bda2c074c04299187af6333 From 5758f12a88dd03d15c412dbc001d49745893935a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 30 May 2022 22:15:00 +0900 Subject: [PATCH 2/2] Move Vrm10Instance.SpringBoneCenter to Vrm10InstanceSpringBone.Spring.Center. Update exporter and importer. --- .../Runtime/Components/Vrm10Instance/Vrm10Instance.cs | 3 --- .../Vrm10Instance/Vrm10InstanceSpringBone.cs | 3 +++ .../Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs | 2 +- Assets/VRM10/Runtime/IO/Vrm10Exporter.cs | 10 ++++++++++ Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 5 +++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index a5e9b335b..ac9b744ff 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -38,9 +38,6 @@ namespace UniVRM10 [SerializeField, Header("Runtime")] public UpdateTypes UpdateType = UpdateTypes.LateUpdate; - [SerializeField] - public Transform SpringBoneCenter; - [SerializeField, Header("LookAt")] public bool DrawLookAtGizmo = true; diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs index 98b63e900..28aaca1f5 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10InstanceSpringBone.cs @@ -33,6 +33,9 @@ namespace UniVRM10 [SerializeField] public List Joints = new List(); + [SerializeField] + public Transform Center; + public Spring(string name) { Name = name; diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 1f18f0e81..efaefef26 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -72,7 +72,7 @@ namespace UniVRM10 return new FastSpringBoneBuffer( springBone.Springs.Select(spring => new FastSpringBoneSpring { - center = m_target.SpringBoneCenter, + center = spring.Center, colliders = spring.ColliderGroups .SelectMany(group => group.Colliders) .Select(collider => new FastSpringBoneCollider diff --git a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs index 4ee8e1ece..0bfb0ebef 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs @@ -394,6 +394,16 @@ namespace UniVRM10 Joints = x.Joints.Select(y => ExportJoint(y, getNodeIndexFromTransform)).ToList(), ColliderGroups = x.ColliderGroups.Select(y => controller.SpringBone.ColliderGroups.IndexOf(y)).ToArray(), }; + + if (x.Center != null) + { + var center = model.Nodes.IndexOf(converter.Nodes[x.Center.gameObject]); + if (center != -1) + { + spring.Center = center; + } + } + springBone.Springs.Add(spring); } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 3f6265fa0..99f68bfa8 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -595,6 +595,11 @@ namespace UniVRM10 var spring = new Vrm10InstanceSpringBone.Spring(gltfSpring.Name); controller.SpringBone.Springs.Add(spring); + if (gltfSpring.Center.HasValue) + { + spring.Center = Nodes[gltfSpring.Center.Value]; + } + if (gltfSpring.ColliderGroups != null) { spring.ColliderGroups = gltfSpring.ColliderGroups.Select(x => controller.SpringBone.ColliderGroups[x]).ToList();