diff --git a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs index a937e80e9..317ceddda 100644 --- a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs +++ b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs @@ -1,6 +1,5 @@ using System; using System.Text; -using UniGLTF.Extensions.VRMC_node_constraint; using UnityEditor; using UnityEngine; @@ -36,12 +35,9 @@ namespace UniVRM10 void DrawDstCurrent() { var s = m_target.transform.lossyScale.x; - - // current - Handles.matrix = m_target.transform.localToWorldMatrix; + Handles.matrix = m_target.GetDstCurrent().TRS(0.05f * s); Handles.color = Color.yellow; - var size = 0.05f / s; - Handles.DrawWireCube(Vector3.zero, new Vector3(size, size, size)); + Handles.DrawWireCube(Vector3.zero, Vector3.one); } void DrawDstCoords() diff --git a/Assets/VRM10/Runtime/Components/Constraint/TR.cs b/Assets/VRM10/Runtime/Components/Constraint/TR.cs index d914f0e2f..c5c968c91 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/TR.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/TR.cs @@ -18,7 +18,7 @@ namespace UniVRM10 var toRelative = from.worldToLocalMatrix; return new TR(toRelative.rotation * t.rotation, toRelative.MultiplyPoint(t.position)); } - + public TR(Quaternion r, Vector3 t) { Rotation = r; @@ -31,6 +31,6 @@ namespace UniVRM10 public Matrix4x4 TRS(float s) => Matrix4x4.TRS(Translation, Rotation, new Vector3(s, s, s)); - public static TR operator *(TR a, TR b) => new TR(a.Rotation * b.Rotation, b.Rotation * a.Translation + b.Translation); + public static TR operator *(TR a, TR b) => new TR(a.Rotation * b.Rotation, a.Rotation * b.Translation + a.Translation); } } diff --git a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs index b3cb56c36..24c80d31d 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs @@ -94,59 +94,15 @@ namespace UniVRM10 public TR GetSourceCurrent() { - switch (SourceCoordinate) + var coords = GetSourceCoords(); + if (m_src != null) { - case ObjectSpace.model: - { - var r = Quaternion.identity; - if (Source != null) - { - if (ModelRoot != null) - { - r = ModelRoot.rotation; - if (m_src != null) - { - r *= m_src.RotationDelta(ObjectSpace.model); - } - } - } - - var t = Vector3.zero; - if (Source != null) - { - t = Source.position; - } - - return new TR(r, t); - } - - case ObjectSpace.local: - { - if (Source != null) - { - if (m_src != null) - { - // runtime - var parent = Quaternion.identity; - if (Source.parent != null) - { - parent = Source.parent.rotation; - } - var delta = m_src.RotationDelta(ObjectSpace.local); - - return new TR(parent * m_src.LocalInitial.Rotation * delta, Source.position); - } - else - { - return TR.FromWorld(Source); - } - } - - return TR.Identity; - } + return coords * new TR(m_src.RotationDelta(SourceCoordinate)); + } + else + { + return coords; } - - throw new NotImplementedException(); } public Quaternion Delta @@ -180,7 +136,7 @@ namespace UniVRM10 { parent = TR.FromWorld(transform.parent); } - return m_dst.LocalInitial * parent; + return parent * m_dst.LocalInitial; } else { @@ -192,6 +148,51 @@ namespace UniVRM10 throw new NotImplementedException(); } + public TR GetDstCurrent() + { + var coords = GetDstCoords(); + if (m_src != null) + { + return coords * new TR(m_src.RotationDelta(SourceCoordinate)); + } + else + { + return coords; + } + // switch (DestinationCoordinate) + // { + // case ObjectSpace.model: + // { + // var r = Quaternion.identity; + // if (ModelRoot != null) + // { + // r = ModelRoot.rotation; + // } + // return new TR(r, transform.position); + // } + + // case ObjectSpace.local: + // { + // if (m_src != null) + // { + // // runtime + // var parent = TR.Identity; + // if (transform.parent != null) + // { + // parent = TR.FromWorld(transform.parent); + // } + // return parent * m_dst.LocalInitial; + // } + // else + // { + // return TR.FromWorld(transform); + // } + // } + // } + + // throw new NotImplementedException(); + } + /// /// Editorで設定値の変更を反映するために、クリアする ///