diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs index c0d641a58..bb9a4da1c 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs @@ -73,7 +73,7 @@ namespace UniVRM10 } #region INormalizedPoseApplicable - public void SetHipsPosition(Vector3 position) + public void SetRawHipsPosition(Vector3 position) { var world = _controlRigRoot.TransformPoint(position); _hipBone.ControlBone.position = world; @@ -102,7 +102,7 @@ namespace UniVRM10 } #region ITPoseProvider - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBones() + public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() { foreach (var headParent in Traverse(_hipBone)) { @@ -112,12 +112,12 @@ namespace UniVRM10 public Vector3 HipTPoseWorldPosition { get; } - public Quaternion GetBoneTPoseWorldRotation(HumanBodyBones bone) + public Quaternion GetBoneWorldRotation(HumanBodyBones bone) { return Quaternion.identity; } - public Vector3 GetBoneTPoseWorldPosition(HumanBodyBones bone) + public Vector3 GetBoneWorldPosition(HumanBodyBones bone) { return _bones[bone].InitialTargetGlobalPosition; } diff --git a/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs index b29fd971c..fc49e89cf 100644 --- a/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs @@ -55,7 +55,7 @@ namespace UniVRM10 } } - public Vector3 GetHipsPosition() + public Vector3 GetRawHipsPosition() { // TODO: from model root ? return m_animator.GetBoneTransform(HumanBodyBones.Hips).localPosition; @@ -65,17 +65,17 @@ namespace UniVRM10 #region ITPoseProvider public Vector3 HipTPoseWorldPosition { get; } - public Quaternion GetBoneTPoseWorldRotation(HumanBodyBones bone) + public Quaternion GetBoneWorldRotation(HumanBodyBones bone) { throw new System.NotImplementedException(); } - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBones() + public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() { throw new System.NotImplementedException(); } - public Vector3 GetBoneTPoseWorldPosition(HumanBodyBones bone) + public Vector3 GetBoneWorldPosition(HumanBodyBones bone) { return m_posMap[bone]; } diff --git a/Assets/VRM10/Runtime/ControlRig/INormalizedPoseApplicable.cs b/Assets/VRM10/Runtime/ControlRig/INormalizedPoseApplicable.cs index 6d265a60f..30367b223 100644 --- a/Assets/VRM10/Runtime/ControlRig/INormalizedPoseApplicable.cs +++ b/Assets/VRM10/Runtime/ControlRig/INormalizedPoseApplicable.cs @@ -5,7 +5,7 @@ namespace UniVRM10 { public interface INormalizedPoseApplicable { - void SetHipsPosition(Vector3 position); + void SetRawHipsPosition(Vector3 position); void SetNormalizedLocalRotation(HumanBodyBones bone, Quaternion normalizedLocalRotation); } diff --git a/Assets/VRM10/Runtime/ControlRig/INormalizedPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/INormalizedPoseProvider.cs index 798b3e610..a4b6b6b9c 100644 --- a/Assets/VRM10/Runtime/ControlRig/INormalizedPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/INormalizedPoseProvider.cs @@ -7,7 +7,7 @@ namespace UniVRM10 /// /// Get hips position in model root space /// - Vector3 GetHipsPosition(); + Vector3 GetRawHipsPosition(); /// /// Get normalized local rotation diff --git a/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs index 56c8c87b1..c5c2a8c7a 100644 --- a/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs @@ -5,31 +5,26 @@ namespace UniVRM10 { public interface ITPoseProvider { - /// - /// * world は ModelRoot を意図していることに注意 - /// - Vector3 HipTPoseWorldPosition { get; } - - /// - /// * world は ModelRoot を意図していることに注意 - /// * bone 無いときは Quaternion.Identity ? - /// - /// - /// - Quaternion GetBoneTPoseWorldRotation(HumanBodyBones bone); - - /// - /// * world は ModelRoot を意図していることに注意 - /// * bone 無いときは Vector3.zero ? - /// - /// - /// - Vector3 GetBoneTPoseWorldPosition(HumanBodyBones bone); - /// /// ボーンを親ボーンとセットで列挙する /// /// hips の場合は parent は HumanBodyBones.LastBone で null を表す - IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBones(); + IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs(); + + /// + /// * bone 無いときは throw するべし + /// * EnumerateBoneParentPairs で事前に有無を確認できる + /// + /// + /// + Quaternion GetBoneWorldRotation(HumanBodyBones bone); + + /// + /// * bone 無いときは throw するべし + /// * EnumerateBoneParentPairs で事前に有無を確認できる + /// + /// + /// + Vector3 GetBoneWorldPosition(HumanBodyBones bone); } } diff --git a/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs index 7ebbad0d8..62fb26a49 100644 --- a/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs @@ -44,7 +44,7 @@ namespace UniVRM10 } } - public Vector3 GetHipsPosition() + public Vector3 GetRawHipsPosition() { if (m_hips.parent == m_root) { @@ -56,17 +56,17 @@ namespace UniVRM10 } } - public Quaternion GetBoneTPoseWorldRotation(HumanBodyBones bone) + public Quaternion GetBoneWorldRotation(HumanBodyBones bone) { throw new System.NotImplementedException(); } - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBones() + public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() { throw new System.NotImplementedException(); } - public Vector3 GetBoneTPoseWorldPosition(HumanBodyBones bone) + public Vector3 GetBoneWorldPosition(HumanBodyBones bone) { throw new System.NotImplementedException(); } diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs index 8875c1bcb..d21ff2a63 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs @@ -6,26 +6,26 @@ namespace UniVRM10 { public static void Retarget((INormalizedPoseProvider Pose, ITPoseProvider TPose) source, (INormalizedPoseApplicable Pose, ITPoseProvider TPose) sink) { - foreach (var (head, parent) in sink.TPose.EnumerateBones()) + foreach (var (head, parent) in sink.TPose.EnumerateBoneParentPairs()) { var q = source.Pose.GetNormalizedLocalRotation(head, parent); sink.Pose.SetNormalizedLocalRotation(head, q); } // scaling hips position - var scaling = sink.TPose.GetBoneTPoseWorldPosition(HumanBodyBones.LeftUpperLeg).y / source.TPose.GetBoneTPoseWorldPosition(HumanBodyBones.LeftUpperLeg).y; - var delta = source.Pose.GetHipsPosition() - source.TPose.HipTPoseWorldPosition; - sink.Pose.SetHipsPosition(sink.TPose.HipTPoseWorldPosition + delta * scaling); + var scaling = sink.TPose.GetBoneWorldPosition(HumanBodyBones.LeftUpperLeg).y / source.TPose.GetBoneWorldPosition(HumanBodyBones.LeftUpperLeg).y; + var delta = source.Pose.GetRawHipsPosition() - source.TPose.GetBoneWorldPosition(HumanBodyBones.Hips); + sink.Pose.SetRawHipsPosition(sink.TPose.GetBoneWorldPosition(HumanBodyBones.Hips) + delta * scaling); } public static void EnforceTPose((INormalizedPoseApplicable Pose, ITPoseProvider TPose) sink) { - foreach (var (head, parent) in sink.TPose.EnumerateBones()) + foreach (var (head, parent) in sink.TPose.EnumerateBoneParentPairs()) { sink.Pose.SetNormalizedLocalRotation(head, Quaternion.identity); } - sink.Pose.SetHipsPosition(sink.TPose.HipTPoseWorldPosition); + sink.Pose.SetRawHipsPosition(sink.TPose.GetBoneWorldPosition(HumanBodyBones.Hips)); } } }