From 83c407a42f31732dac28f1814695f3b41b3eff5e Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 16:29:13 +0900 Subject: [PATCH 1/4] VRM10SpringSelectorWindow --- .../SpringBone/VRM10SpringSelectorWindow.cs | 97 +++++++++++++++++++ .../VRM10SpringSelectorWindow.cs.meta | 11 +++ 2 files changed, 108 insertions(+) create mode 100644 Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs create mode 100644 Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs.meta diff --git a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs new file mode 100644 index 000000000..f7e7f47dc --- /dev/null +++ b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs @@ -0,0 +1,97 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace UniVRM10 +{ + /// + /// ヒエラルキーから VRM10SpringBone と VRM10ColliderGroup を集めてリスト表示する + /// + public class VRM10SpringSelectorWindow : EditorWindow + { + const string MENU_KEY = VRMVersion.MENU + "/SpringBone"; + + [MenuItem(MENU_KEY, false, 0)] + private static void ExportFromMenu() + { + var window = (VRM10SpringSelectorWindow)GetWindow(typeof(VRM10SpringSelectorWindow)); + window.titleContent = new GUIContent("SpringBone selector"); + window.Show(); + } + + void OnEnable() + { + // Debug.Log("OnEnable"); + Undo.willFlushUndoRecord += Repaint; + Selection.selectionChanged += Repaint; + } + + void OnDisable() + { + // Debug.Log("OnDisable"); + Selection.selectionChanged -= Repaint; + Undo.willFlushUndoRecord -= Repaint; + } + + Transform m_root; + Transform Root + { + get => m_root; + set + { + if (m_root == value) + { + return; + } + if (value != null && !value.gameObject.scene.IsValid()) + { + // skip prefab + return; + } + m_root = value; + if (m_root != null) + { + m_springs = m_root.GetComponentsInChildren(); + m_colliderGroups = m_root.GetComponentsInChildren(); + } + } + } + + static bool s_foldSprings = true; + public VRM10SpringBone[] m_springs; + + static bool s_foldColliders = true; + public VRM10SpringBoneColliderGroup[] m_colliderGroups; + + + private void OnGUI() + { + Root = (Transform)EditorGUILayout.ObjectField(m_root, typeof(Transform), true); + + GUI.enabled = false; + s_foldSprings = EditorGUILayout.Foldout(s_foldSprings, "springs"); + if (s_foldSprings) + { + if (m_springs != null) + { + foreach (var s in m_springs) + { + EditorGUILayout.ObjectField(s, typeof(VRM10SpringBone), true); + } + } + } + + s_foldColliders = EditorGUILayout.Foldout(s_foldColliders, "colliders"); + if (s_foldColliders) + { + if (m_colliderGroups != null) + { + foreach (var c in m_colliderGroups) + { + EditorGUILayout.ObjectField(c, typeof(VRM10SpringBoneColliderGroup), true); + } + } + } + } + } +} diff --git a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs.meta b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs.meta new file mode 100644 index 000000000..9bbae3601 --- /dev/null +++ b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a38b6d598e4f6c9458cd0a819302b438 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From fc5e7676809875afe645d063ce48a73db684261d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 17:00:36 +0900 Subject: [PATCH 2/4] OnDrawGizmosSelected --- .../Runtime/Components/SpringBone/VRM10SpringBone.cs | 7 +++++-- .../SpringBone/VRM10SpringBoneColliderGroup.cs | 7 +++++-- .../Runtime/Components/SpringBone/VRM10SpringJoint.cs | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs index f834791c5..e72f8e657 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs @@ -19,6 +19,9 @@ namespace UniVRM10 [Serializable] public class VRM10SpringBone : MonoBehaviour { + [SerializeField] + Color m_gizmoColor = Color.yellow; + [SerializeField] public string Comment; @@ -100,13 +103,13 @@ namespace UniVRM10 } } - public void DrawGizmo(Color color) + public void OnDrawGizmosSelected() { foreach (var joint in Joints) { if (joint != null) { - joint.DrawGizmo(m_center, color); + joint.DrawGizmo(m_center, m_gizmoColor); } } } diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs index 149f59bde..221f896d5 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBoneColliderGroup.cs @@ -10,6 +10,9 @@ namespace UniVRM10 [AddComponentMenu("VRM10/VRM10SpringBoneColliderGroup")] public class VRM10SpringBoneColliderGroup : MonoBehaviour { + [SerializeField] + Color m_gizmoColor = Color.cyan; + [SerializeField] public List Colliders = new List(); @@ -61,9 +64,9 @@ namespace UniVRM10 } } - public void DrawGizmos(Color color) + public void OnDrawGizmosSelected() { - Gizmos.color = color; + Gizmos.color = m_gizmoColor; Matrix4x4 mat = transform.localToWorldMatrix; Gizmos.matrix = mat * Matrix4x4.Scale(new Vector3( 1.0f / transform.lossyScale.x, diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringJoint.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringJoint.cs index 88214a493..d37cc2c49 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringJoint.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringJoint.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace UniVRM10 { @@ -43,7 +46,11 @@ namespace UniVRM10 } else { - // TODO +#if UNITY_EDITOR + // Gizmos.matrix = Transform.localToWorldMatrix; + Gizmos.color = color; + Gizmos.DrawSphere(Transform.position, m_jointRadius); +#endif } } From a03f4232133fc00f27ec4b83ab6e941f6799d3d9 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 17:05:53 +0900 Subject: [PATCH 3/4] auto reload --- .../SpringBone/VRM10SpringSelectorWindow.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs index f7e7f47dc..747493bca 100644 --- a/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs +++ b/Assets/VRM10/Editor/Components/SpringBone/VRM10SpringSelectorWindow.cs @@ -63,10 +63,21 @@ namespace UniVRM10 static bool s_foldColliders = true; public VRM10SpringBoneColliderGroup[] m_colliderGroups; + void Reload() + { + var backup = Root; + Root = null; + Root = backup; + } private void OnGUI() { - Root = (Transform)EditorGUILayout.ObjectField(m_root, typeof(Transform), true); + Root = (Transform)EditorGUILayout.ObjectField("vrm1 root", m_root, typeof(Transform), true); + + if (m_springs != null && m_springs.Length > 0 && m_springs[0] == null) + { + Reload(); + } GUI.enabled = false; s_foldSprings = EditorGUILayout.Foldout(s_foldSprings, "springs"); From cff9dfadd83b3633e3e319f808a689036bbd499a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 17:12:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?VRM10SpringBone.m=5Fcenter=20=E3=82=92=20VR?= =?UTF-8?q?M10Controller.SpringBoneCenter=20=E3=81=AB=E7=A7=BB=E5=8B=95=20?= =?UTF-8?q?(Spring=E3=81=94=E3=81=A8=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8FMo?= =?UTF-8?q?del=E5=85=A8=E4=BD=93=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=81=AB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit springの設定ではなくて、springが動く環境の設定。アプリが任意に設定する想定。 --- .../Runtime/Components/SpringBone/VRM10SpringBone.cs | 12 ++++++------ Assets/VRM10/Runtime/Components/VRM10Controller.cs | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs index e72f8e657..f87ea8048 100644 --- a/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs +++ b/Assets/VRM10/Runtime/Components/SpringBone/VRM10SpringBone.cs @@ -31,9 +31,6 @@ namespace UniVRM10 [SerializeField] public List ColliderGroups = new List(); - [SerializeField] - public Transform m_center; - [ContextMenu("Reset bones")] public void ResetJoints() { @@ -46,9 +43,12 @@ namespace UniVRM10 } } + Transform m_center; + List m_colliderList = new List(); - public void Process() + public void Process(Transform center) { + m_center = center; if (Joints == null) { return; @@ -96,10 +96,10 @@ namespace UniVRM10 VRM10SpringJoint lastJoint = Joints.FirstOrDefault(x => x != null); foreach (var joint in Joints.Where(x => x != null).Skip(1)) { - lastJoint.Update(m_center, Time.deltaTime, m_colliderList, joint); + lastJoint.Update(center, Time.deltaTime, m_colliderList, joint); lastJoint = joint; } - lastJoint.Update(m_center, Time.deltaTime, m_colliderList, null); + lastJoint.Update(center, Time.deltaTime, m_colliderList, null); } } diff --git a/Assets/VRM10/Runtime/Components/VRM10Controller.cs b/Assets/VRM10/Runtime/Components/VRM10Controller.cs index 631a89290..bc4be32e0 100644 --- a/Assets/VRM10/Runtime/Components/VRM10Controller.cs +++ b/Assets/VRM10/Runtime/Components/VRM10Controller.cs @@ -27,6 +27,9 @@ namespace UniVRM10 [SerializeField, Header("UpdateSetting")] public UpdateTypes UpdateType = UpdateTypes.LateUpdate; + + [SerializeField, Header("SpringBone")] + public Transform SpringBoneCenter; } [SerializeField] @@ -128,7 +131,7 @@ namespace UniVRM10 } foreach (var spring in m_springs) { - spring.Process(); + spring.Process(Controller.SpringBoneCenter); } //