diff --git a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs index 08d430ba5..a937e80e9 100644 --- a/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs +++ b/Assets/VRM10/Editor/Components/Constraint/VRM10RotationConstraintEditor.cs @@ -20,12 +20,9 @@ namespace UniVRM10 void DrawSourceCurrent() { var s = m_target.transform.lossyScale.x; - - // current - Handles.matrix = m_target.Source.localToWorldMatrix; + Handles.matrix = m_target.GetSourceCurrent().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 DrawSourceCoords() diff --git a/Assets/VRM10/Runtime/Components/Constraint/ConstraintSource.cs b/Assets/VRM10/Runtime/Components/Constraint/ConstraintSource.cs index 43d684393..0c0f3389d 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/ConstraintSource.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/ConstraintSource.cs @@ -34,10 +34,9 @@ namespace UniVRM10 { switch (coords) { - // 右からかけるか、左からかけるか、それが問題なのだ // case SourceCoordinates.World: return m_transform.rotation * Quaternion.Inverse(m_initial.Rotation); case ObjectSpace.local: return m_transform.localRotation * Quaternion.Inverse(LocalInitial.Rotation); - case ObjectSpace.model: return m_transform.rotation * Quaternion.Inverse(ModelRoot.rotation) * Quaternion.Inverse(ModelInitial.Rotation); + case ObjectSpace.model: return m_transform.rotation * Quaternion.Inverse(ModelInitial.Rotation) * Quaternion.Inverse(ModelRoot.rotation); default: throw new NotImplementedException(); } } diff --git a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs index 14ab8a139..da13a5ea2 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/VRM10RotationConstraint.cs @@ -92,6 +92,61 @@ namespace UniVRM10 throw new NotImplementedException(); } + public TR GetSourceCurrent() + { + switch (SourceCoordinate) + { + 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 = TR.Identity; + if (Source.parent != null) + { + parent = TR.FromWorld(Source.parent); + } + return parent * m_src.LocalInitial; + } + else + { + return TR.FromWorld(Source); + } + } + + return TR.Identity; + } + } + + throw new NotImplementedException(); + } + public Quaternion Delta { get;