From 2469d65cb29e7528ada8cedf5da0daf1ac71dcd3 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 13 May 2021 14:41:12 +0900 Subject: [PATCH] IVRM10SourceDestination --- ...10ConstraintSourceDestinationExtensions.cs | 59 +++++++++++++++ ...straintSourceDestinationExtensions.cs.meta | 11 +++ .../VRM10RotationConstraintEditor.cs | 74 ++++++------------- .../Constraint/IVRM10SourceDestination.cs | 11 +++ .../IVRM10SourceDestination.cs.meta | 11 +++ .../Constraint/VRM10RotationConstraint.cs | 6 +- 6 files changed, 117 insertions(+), 55 deletions(-) create mode 100644 Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs create mode 100644 Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs.meta create mode 100644 Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs create mode 100644 Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs.meta diff --git a/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs b/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs new file mode 100644 index 000000000..38e3c6a0b --- /dev/null +++ b/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs @@ -0,0 +1,59 @@ +using UnityEditor; +using UnityEngine; + +namespace UniVRM10 +{ + public static class IVRM10ConstraintSourceDestinationExtensions + { + public static void DrawSourceCoords(this IVRM10ConstraintSourceDestination self) + { + try + { + self.GetSourceCoords().Draw(0.2f); + } + catch (ConstraintException) + { + + } + } + public static void DrawSourceCurrent(this IVRM10ConstraintSourceDestination self) + { + try + { + Handles.matrix = self.GetSourceCurrent().TRS(0.05f); + Handles.color = Color.yellow; + Handles.DrawWireCube(Vector3.zero, Vector3.one); + } + catch (ConstraintException) + { + + } + } + + public static void DrawDstCoords(this IVRM10ConstraintSourceDestination self) + { + try + { + self.GetDstCoords().Draw(0.2f); + } + catch (ConstraintException) + { + + } + } + + public static void DrawDstCurrent(this IVRM10ConstraintSourceDestination self) + { + try + { + Handles.matrix = self.GetDstCurrent().TRS(0.05f); + Handles.color = Color.yellow; + Handles.DrawWireCube(Vector3.zero, Vector3.one); + } + catch (ConstraintException) + { + + } + } + } +} diff --git a/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs.meta b/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs.meta new file mode 100644 index 000000000..a2836e116 --- /dev/null +++ b/Assets/VRM10/Editor/Components/Constraint/IVRM10ConstraintSourceDestinationExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59e1ae1f9d4fb9a459cd2c97a4351b1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs index 317ceddda..c0503738c 100644 --- a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs +++ b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs @@ -1,4 +1,3 @@ -using System; using System.Text; using UnityEditor; using UnityEngine; @@ -15,39 +14,18 @@ namespace UniVRM10 m_target = (VRM10RotationConstraint)target; } - #region SRC - void DrawSourceCurrent() - { - var s = m_target.transform.lossyScale.x; - Handles.matrix = m_target.GetSourceCurrent().TRS(0.05f * s); - Handles.color = Color.yellow; - Handles.DrawWireCube(Vector3.zero, Vector3.one); - } - - void DrawSourceCoords() - { - var s = m_target.transform.lossyScale.x; - m_target.GetSourceCoords().Draw(0.2f / s); - } - #endregion - - #region Dst - void DrawDstCurrent() - { - var s = m_target.transform.lossyScale.x; - Handles.matrix = m_target.GetDstCurrent().TRS(0.05f * s); - Handles.color = Color.yellow; - Handles.DrawWireCube(Vector3.zero, Vector3.one); - } - - void DrawDstCoords() - { - var s = m_target.transform.lossyScale.x; - m_target.GetDstCoords().Draw(0.2f / s); - } - #endregion - static GUIStyle s_style; + static GUIStyle Style + { + get + { + if (s_style == null) + { + s_style = new GUIStyle("box"); + } + return s_style; + } + } /// /// Euler各を +- 180 にクランプする @@ -74,16 +52,12 @@ namespace UniVRM10 { return; } - if (s_style == null) - { - s_style = new GUIStyle("box"); - } // this to target line Handles.color = Color.yellow; Handles.DrawLine(m_target.Source.position, m_target.transform.position); - var euler = Clamp180(m_target.Delta.eulerAngles); + var delta = Clamp180(m_target.Delta.eulerAngles); // show source { @@ -91,26 +65,26 @@ namespace UniVRM10 sb.AppendLine(); sb.AppendLine(); sb.AppendLine($"source: {m_target.SourceCoordinate}"); - sb.AppendLine($"{euler.x:0.}"); - sb.AppendLine($"{euler.y:0.}"); - sb.Append($"{euler.z:0.}"); - Handles.Label(m_target.Source.position, sb.ToString(), s_style); + sb.AppendLine($"{delta.x:0.}"); + sb.AppendLine($"{delta.y:0.}"); + sb.Append($"{delta.z:0.}"); + Handles.Label(m_target.Source.position, sb.ToString(), Style); } // show dst { var sb = new StringBuilder(); sb.AppendLine($"constraint: {m_target.DestinationCoordinate}"); - sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.X) ? $"freeze" : $"{euler.x:0.}"); - sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.Y) ? $"freeze" : $"{euler.y:0.}"); - sb.Append(m_target.FreezeAxes.HasFlag(AxisMask.Z) ? $"freeze" : $"{euler.z:0.}"); - Handles.Label(m_target.transform.position, sb.ToString(), s_style); + sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.X) ? $"freeze" : $"{delta.x:0.}"); + sb.AppendLine(m_target.FreezeAxes.HasFlag(AxisMask.Y) ? $"freeze" : $"{delta.y:0.}"); + sb.Append(m_target.FreezeAxes.HasFlag(AxisMask.Z) ? $"freeze" : $"{delta.z:0.}"); + Handles.Label(m_target.transform.position, sb.ToString(), Style); } - DrawSourceCoords(); - DrawSourceCurrent(); - DrawDstCoords(); - DrawDstCurrent(); + m_target.DrawSourceCoords(); + m_target.DrawSourceCurrent(); + m_target.DrawDstCoords(); + m_target.DrawDstCurrent(); } } } diff --git a/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs b/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs new file mode 100644 index 000000000..d6aa2ca89 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs @@ -0,0 +1,11 @@ +namespace UniVRM10 +{ + public interface IVRM10ConstraintSourceDestination + { + TR GetSourceCoords(); + TR GetSourceCurrent(); + + TR GetDstCoords(); + TR GetDstCurrent(); + } +} diff --git a/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs.meta b/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs.meta new file mode 100644 index 000000000..ff49caec8 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Constraint/IVRM10SourceDestination.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d1ea0f0f4d95a2499f9aa5a1d7a2235 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs index 24c80d31d..635ff3782 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs @@ -9,7 +9,7 @@ namespace UniVRM10 /// 対象の初期回転と現在回転の差分(delta)を、自身の初期回転と自身の初期回転にdeltaを乗算したものに対してWeightでSlerpする。 /// [DisallowMultipleComponent] - public class VRM10RotationConstraint : VRM10Constraint + public class VRM10RotationConstraint : VRM10Constraint, IVRM10ConstraintSourceDestination { [SerializeField] public Transform Source = default; @@ -36,10 +36,6 @@ namespace UniVRM10 ConstraintSource m_src; - /// - /// Source の座標系 - /// - /// public TR GetSourceCoords() { switch (SourceCoordinate)