From d329e3cb89a5e19b666e1571ad111c3e8650e7aa Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Feb 2023 15:33:51 +0900 Subject: [PATCH] =?UTF-8?q?ITPoseProvider=20=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bone, parent * Quaternion?, Vector3? にして throw しない * Vrm10RuntimeControlRig のインターフェース実装でない property を削り --- .../ControlRig/Vrm10RuntimeControlRig.cs | 12 +++------- .../ControlRig/AnimatorPoseProvider.cs | 6 ++--- .../Runtime/ControlRig/ITPoseProvider.cs | 24 ++++++------------- .../ControlRig/InitialRotationPoseProvider.cs | 6 ++--- .../VRM10Viewer/VRM10Retarget.cs | 14 +++++------ 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs index bb9a4da1c..5af0d7732 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10RuntimeControlRig.cs @@ -23,8 +23,6 @@ namespace UniVRM10 public IReadOnlyDictionary Bones => _bones; public Animator ControlRigAnimator { get; } - public float InitialHipsHeight => HipTPoseWorldPosition.y; - /// /// humanoid に対して ControlRig を生成します /// @@ -38,8 +36,6 @@ namespace UniVRM10 _hipBone = Vrm10ControlBone.Build(humanoid, out _bones, _controlRigRoot); _hipBone.ControlBone.SetParent(_controlRigRoot); - HipTPoseWorldPosition = vrmRoot.worldToLocalMatrix.MultiplyPoint(_hipBone.ControlTarget.position); - var transformBonePairs = _bones.Select(kv => (kv.Value.ControlBone, kv.Key)); _controlRigAvatar = HumanoidLoader.LoadHumanoidAvatar(vrmRoot, transformBonePairs); _controlRigAvatar.name = "Runtime Control Rig"; @@ -102,7 +98,7 @@ namespace UniVRM10 } #region ITPoseProvider - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() + public IEnumerable<(HumanBodyBones Bone, HumanBodyBones Parent)> EnumerateBoneParentPairs() { foreach (var headParent in Traverse(_hipBone)) { @@ -110,14 +106,12 @@ namespace UniVRM10 } } - public Vector3 HipTPoseWorldPosition { get; } - - public Quaternion GetBoneWorldRotation(HumanBodyBones bone) + public Quaternion? GetBoneWorldRotation(HumanBodyBones bone) { return Quaternion.identity; } - public Vector3 GetBoneWorldPosition(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 fc49e89cf..90742e54a 100644 --- a/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/AnimatorPoseProvider.cs @@ -65,17 +65,17 @@ namespace UniVRM10 #region ITPoseProvider public Vector3 HipTPoseWorldPosition { get; } - public Quaternion GetBoneWorldRotation(HumanBodyBones bone) + public IEnumerable<(HumanBodyBones Bone, HumanBodyBones Parent)> EnumerateBoneParentPairs() { throw new System.NotImplementedException(); } - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() + public Quaternion? GetBoneWorldRotation(HumanBodyBones bone) { throw new System.NotImplementedException(); } - public Vector3 GetBoneWorldPosition(HumanBodyBones bone) + public Vector3? GetBoneWorldPosition(HumanBodyBones bone) { return m_posMap[bone]; } diff --git a/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs index c5c2a8c7a..1ffe5f60a 100644 --- a/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/ITPoseProvider.cs @@ -6,25 +6,15 @@ namespace UniVRM10 public interface ITPoseProvider { /// - /// ボーンを親ボーンとセットで列挙する + /// このTPoseに含まれるボーンと親ボーンの組み合わせを列挙する。 + /// + /// * Humanoidの木構造を深さ優先の順番で列挙する + /// /// /// hips の場合は parent は HumanBodyBones.LastBone で null を表す - IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs(); + IEnumerable<(HumanBodyBones Bone, HumanBodyBones Parent)> EnumerateBoneParentPairs(); - /// - /// * bone 無いときは throw するべし - /// * EnumerateBoneParentPairs で事前に有無を確認できる - /// - /// - /// - Quaternion GetBoneWorldRotation(HumanBodyBones bone); - - /// - /// * bone 無いときは throw するべし - /// * EnumerateBoneParentPairs で事前に有無を確認できる - /// - /// - /// - Vector3 GetBoneWorldPosition(HumanBodyBones bone); + Quaternion? GetBoneWorldRotation(HumanBodyBones bone); + Vector3? GetBoneWorldPosition(HumanBodyBones bone); } } diff --git a/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs b/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs index 62fb26a49..a2d01d06a 100644 --- a/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs +++ b/Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs @@ -56,17 +56,17 @@ namespace UniVRM10 } } - public Quaternion GetBoneWorldRotation(HumanBodyBones bone) + public IEnumerable<(HumanBodyBones Bone, HumanBodyBones Parent)> EnumerateBoneParentPairs() { throw new System.NotImplementedException(); } - public IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs() + public Quaternion? GetBoneWorldRotation(HumanBodyBones bone) { throw new System.NotImplementedException(); } - public Vector3 GetBoneWorldPosition(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 d21ff2a63..7825fd36e 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Retarget.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace UniVRM10 +namespace UniVRM10.VRM10Viewer { public static class VRM10Retarget { @@ -13,19 +13,19 @@ namespace UniVRM10 } // scaling hips position - 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); + var scaling = sink.TPose.GetBoneWorldPosition(HumanBodyBones.LeftUpperLeg).Value.y / source.TPose.GetBoneWorldPosition(HumanBodyBones.LeftUpperLeg).Value.y; + var delta = source.Pose.GetRawHipsPosition() - source.TPose.GetBoneWorldPosition(HumanBodyBones.Hips).Value; + sink.Pose.SetRawHipsPosition(sink.TPose.GetBoneWorldPosition(HumanBodyBones.Hips).Value + delta * scaling); } public static void EnforceTPose((INormalizedPoseApplicable Pose, ITPoseProvider TPose) sink) { - foreach (var (head, parent) in sink.TPose.EnumerateBoneParentPairs()) + foreach (var (bone, parent) in sink.TPose.EnumerateBoneParentPairs()) { - sink.Pose.SetNormalizedLocalRotation(head, Quaternion.identity); + sink.Pose.SetNormalizedLocalRotation(bone, Quaternion.identity); } - sink.Pose.SetRawHipsPosition(sink.TPose.GetBoneWorldPosition(HumanBodyBones.Hips)); + sink.Pose.SetRawHipsPosition(sink.TPose.GetBoneWorldPosition(HumanBodyBones.Hips).Value); } } }