From d9280d0aa506ba1d465098b55cf5e5780f7e3501 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 11 Apr 2022 17:09:43 +0900 Subject: [PATCH 1/3] [ContextMenu("AddJointsToAllChild0")] --- .../SpringBone/VRM10SpringBoneJoint.cs | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs index ec0abade2..df846a000 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs @@ -8,6 +8,7 @@ using UnityEditor; namespace UniVRM10 { [Serializable] + [DisallowMultipleComponent] public class VRM10SpringBoneJoint : MonoBehaviour { [SerializeField, Range(0, 4), Header("Settings")] @@ -27,5 +28,79 @@ namespace UniVRM10 [SerializeField, Range(0, 0.5f), Header("Collision")] public float m_jointRadius = 0.02f; + + void AddJointRecursive(Transform t) + { + var joint = t.gameObject.GetComponent(); + if (joint == null) + { + joint = t.gameObject.AddComponent(); + Debug.Log($"{joint} added"); + } + + if (t.childCount > 0) + { + // only first child + AddJointRecursive(t.GetChild(0)); + } + } + + void GetJoints(Transform t, List joints) + { + var joint = t.GetComponent(); + if (joint != null) + { + joints.Add(joint); + } + + if (t.childCount > 0) + { + GetJoints(t.GetChild(0), joints); + } + } + + [ContextMenu("AddJointsToAllChild0")] + private void AddJointsToChild0() + { + var root = GetComponentInParent(); + if (root == null) + { + Debug.LogWarning("not Vrm10Instance"); + return; + } + + if (transform.childCount == 0) + { + Debug.LogWarning("no children"); + return; + } + + AddJointRecursive(transform.GetChild(0)); + + // updater root + foreach (var spring in root.SpringBone.Springs) + { + for (int i = 0; i < spring.Joints.Count; ++i) + { + if (spring.Joints[i] == this) + { + // found + while (spring.Joints.Count - 1 > i) + { + // remove after this joint + spring.Joints.RemoveAt(spring.Joints.Count - 1); + } + // get descendants joints + var joints = new List(); + GetJoints(transform.GetChild(0), joints); + // add jonits to after this + spring.Joints.AddRange(joints); + return; + } + } + } + + Debug.LogWarning($"{this} is found in {root}"); + } } } From 36d697fdb4d0b5f82b22f6f1bc3182fea2174fbb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 11 Apr 2022 17:13:38 +0900 Subject: [PATCH 2/3] copy settings --- .../SpringBone/VRM10SpringBoneJoint.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs index df846a000..7005d4bbe 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs @@ -23,13 +23,10 @@ namespace UniVRM10 [SerializeField, Range(0, 1)] public float m_dragForce = 0.4f; - [SerializeField] - public bool m_exclude; - [SerializeField, Range(0, 0.5f), Header("Collision")] public float m_jointRadius = 0.02f; - void AddJointRecursive(Transform t) + void AddJointRecursive(Transform t, VRM10SpringBoneJoint src) { var joint = t.gameObject.GetComponent(); if (joint == null) @@ -38,10 +35,17 @@ namespace UniVRM10 Debug.Log($"{joint} added"); } + // copy settings + joint.m_stiffnessForce = src.m_stiffnessForce; + joint.m_gravityPower = src.m_gravityPower; + joint.m_gravityDir = src.m_gravityDir; + joint.m_dragForce = src.m_dragForce; + joint.m_jointRadius = src.m_jointRadius; + if (t.childCount > 0) { // only first child - AddJointRecursive(t.GetChild(0)); + AddJointRecursive(t.GetChild(0), src); } } @@ -75,7 +79,7 @@ namespace UniVRM10 return; } - AddJointRecursive(transform.GetChild(0)); + AddJointRecursive(transform.GetChild(0), this); // updater root foreach (var spring in root.SpringBone.Springs) From f9fa1752ebbd1f828168247c18d9bd8bbb0ab2b1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 11 Apr 2022 17:39:20 +0900 Subject: [PATCH 3/3] simple --- .../VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs index 7005d4bbe..3af0b98cf 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneJoint.cs @@ -63,7 +63,7 @@ namespace UniVRM10 } } - [ContextMenu("AddJointsToAllChild0")] + [ContextMenu("Add joints")] private void AddJointsToChild0() { var root = GetComponentInParent();