WIP OpenXRHandTracking

This commit is contained in:
ousttrue
2022-11-25 22:22:12 +09:00
parent 4a4dbb447a
commit a0d4621547
2 changed files with 46 additions and 30 deletions

View File

@@ -40,6 +40,7 @@ namespace UniVRM10
/// コントロールボーンの初期ローカル回転。
/// </summary>
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;
}
/// <summary>
/// 初期姿勢からの相対的な回転。
///
/// VRM-0.X では localRotation と同じである。
/// </summary>
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;
}
}
/// <summary>
/// 親から再帰的にNormalized の ローカル回転を初期回転を加味して Target に適用する。
/// </summary>
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();

View File

@@ -27,39 +27,39 @@ namespace UniVRM10
public static readonly Dictionary<HumanBodyBones, Quaternion> InitialRotations = new Dictionary<HumanBodyBones, Quaternion>()
{
// 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},
};
}
}