From a0d4621547a6c5a79c871505fa2de4cf6b6b1e21 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 25 Nov 2022 22:22:12 +0900 Subject: [PATCH] WIP OpenXRHandTracking --- .../ControlRig/Vrm10ControlBone.cs | 18 +++++- .../Vrm10Runtime/OpenXRHandTracking.cs | 58 +++++++++---------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 256b1b738..9fd07ca27 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -40,6 +40,7 @@ namespace UniVRM10 /// コントロールボーンの初期ローカル回転。 /// public Quaternion InitialControlBoneLocalRotation { get; } + Quaternion InitialControlBoneGlobalRotation; private readonly Quaternion _initialTargetLocalRotation; private readonly Quaternion _initialTargetGlobalRotation; @@ -77,16 +78,31 @@ namespace UniVRM10 InitialControlBoneLocalPosition = ControlBone.localPosition; InitialControlBoneLocalRotation = ControlBone.localRotation; + InitialControlBoneGlobalRotation = ControlBone.rotation; _initialTargetLocalRotation = controlTarget.localRotation; _initialTargetGlobalRotation = controlTarget.rotation; } + /// + /// 初期姿勢からの相対的な回転。 + /// + /// VRM-0.X では localRotation と同じである。 + /// + Quaternion ControlBoneRelativeRotationFromInitial + { + get + { + var axis = (ControlBone.parent != null ? ControlBone.parent.rotation : Quaternion.identity) * InitialControlBoneLocalRotation; + return InitialControlBoneLocalRotation * Quaternion.Inverse(InitialControlBoneGlobalRotation) * (Quaternion.Inverse(axis) * ControlBone.rotation) * InitialControlBoneGlobalRotation; + } + } + /// /// 親から再帰的にNormalized の ローカル回転を初期回転を加味して Target に適用する。 /// internal void ProcessRecursively() { - ControlTarget.localRotation = _initialTargetLocalRotation * Quaternion.Inverse(_initialTargetGlobalRotation) * ControlBone.localRotation * _initialTargetGlobalRotation; + ControlTarget.localRotation = _initialTargetLocalRotation * (Quaternion.Inverse(_initialTargetGlobalRotation) * ControlBoneRelativeRotationFromInitial * _initialTargetGlobalRotation); foreach (var child in _children) { child.ProcessRecursively(); diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs index 39c296209..9e622a739 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs @@ -27,39 +27,39 @@ namespace UniVRM10 public static readonly Dictionary InitialRotations = new Dictionary() { // Left - // {HumanBodyBones.LeftHand, LeftHand}, - // {HumanBodyBones.LeftThumbProximal, LeftThumb}, - // {HumanBodyBones.LeftThumbIntermediate, LeftThumb}, - // {HumanBodyBones.LeftThumbDistal, LeftThumb}, + {HumanBodyBones.LeftHand, LeftHand}, + {HumanBodyBones.LeftThumbProximal, LeftThumb}, + {HumanBodyBones.LeftThumbIntermediate, LeftThumb}, + {HumanBodyBones.LeftThumbDistal, LeftThumb}, {HumanBodyBones.LeftIndexProximal, LeftHand}, {HumanBodyBones.LeftIndexIntermediate, LeftHand}, {HumanBodyBones.LeftIndexDistal, LeftHand}, - // {HumanBodyBones.LeftMiddleProximal, LeftHand}, - // {HumanBodyBones.LeftMiddleIntermediate, LeftHand}, - // {HumanBodyBones.LeftMiddleDistal, LeftHand}, - // {HumanBodyBones.LeftRingProximal, LeftHand}, - // {HumanBodyBones.LeftRingIntermediate, LeftHand}, - // {HumanBodyBones.LeftRingDistal, LeftHand}, - // {HumanBodyBones.LeftLittleProximal, LeftHand}, - // {HumanBodyBones.LeftLittleIntermediate, LeftHand}, - // {HumanBodyBones.LeftLittleDistal, LeftHand}, + {HumanBodyBones.LeftMiddleProximal, LeftHand}, + {HumanBodyBones.LeftMiddleIntermediate, LeftHand}, + {HumanBodyBones.LeftMiddleDistal, LeftHand}, + {HumanBodyBones.LeftRingProximal, LeftHand}, + {HumanBodyBones.LeftRingIntermediate, LeftHand}, + {HumanBodyBones.LeftRingDistal, LeftHand}, + {HumanBodyBones.LeftLittleProximal, LeftHand}, + {HumanBodyBones.LeftLittleIntermediate, LeftHand}, + {HumanBodyBones.LeftLittleDistal, LeftHand}, // Right - // {HumanBodyBones.RightHand, RightHand}, - // {HumanBodyBones.RightThumbProximal, RightThumb}, - // {HumanBodyBones.RightThumbIntermediate, RightThumb}, - // {HumanBodyBones.RightThumbDistal, RightThumb}, - // {HumanBodyBones.RightIndexProximal, RightHand}, - // {HumanBodyBones.RightIndexIntermediate, RightHand}, - // {HumanBodyBones.RightIndexDistal, RightHand}, - // {HumanBodyBones.RightMiddleProximal, RightHand}, - // {HumanBodyBones.RightMiddleIntermediate, RightHand}, - // {HumanBodyBones.RightMiddleDistal, RightHand}, - // {HumanBodyBones.RightRingProximal, RightHand}, - // {HumanBodyBones.RightRingIntermediate, RightHand}, - // {HumanBodyBones.RightRingDistal, RightHand}, - // {HumanBodyBones.RightLittleProximal, RightHand}, - // {HumanBodyBones.RightLittleIntermediate, RightHand}, - // {HumanBodyBones.RightLittleDistal, RightHand}, + {HumanBodyBones.RightHand, RightHand}, + {HumanBodyBones.RightThumbProximal, RightThumb}, + {HumanBodyBones.RightThumbIntermediate, RightThumb}, + {HumanBodyBones.RightThumbDistal, RightThumb}, + {HumanBodyBones.RightIndexProximal, RightHand}, + {HumanBodyBones.RightIndexIntermediate, RightHand}, + {HumanBodyBones.RightIndexDistal, RightHand}, + {HumanBodyBones.RightMiddleProximal, RightHand}, + {HumanBodyBones.RightMiddleIntermediate, RightHand}, + {HumanBodyBones.RightMiddleDistal, RightHand}, + {HumanBodyBones.RightRingProximal, RightHand}, + {HumanBodyBones.RightRingIntermediate, RightHand}, + {HumanBodyBones.RightRingDistal, RightHand}, + {HumanBodyBones.RightLittleProximal, RightHand}, + {HumanBodyBones.RightLittleIntermediate, RightHand}, + {HumanBodyBones.RightLittleDistal, RightHand}, }; } } \ No newline at end of file