mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-26 13:12:35 -05:00
ITPoseProvider を修正
* bone, parent * Quaternion?, Vector3? にして throw しない * Vrm10RuntimeControlRig のインターフェース実装でない property を削り
This commit is contained in:
parent
1bd8cc4e63
commit
d329e3cb89
|
|
@ -23,8 +23,6 @@ namespace UniVRM10
|
|||
public IReadOnlyDictionary<HumanBodyBones, Vrm10ControlBone> Bones => _bones;
|
||||
public Animator ControlRigAnimator { get; }
|
||||
|
||||
public float InitialHipsHeight => HipTPoseWorldPosition.y;
|
||||
|
||||
/// <summary>
|
||||
/// humanoid に対して ControlRig を生成します
|
||||
/// </summary>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,15 @@ namespace UniVRM10
|
|||
public interface ITPoseProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// ボーンを親ボーンとセットで列挙する</returns>
|
||||
/// このTPoseに含まれるボーンと親ボーンの組み合わせを列挙する。
|
||||
///
|
||||
/// * Humanoidの木構造を深さ優先の順番で列挙する
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>hips の場合は parent は HumanBodyBones.LastBone で null を表す</returns>
|
||||
IEnumerable<(HumanBodyBones Head, HumanBodyBones Parent)> EnumerateBoneParentPairs();
|
||||
IEnumerable<(HumanBodyBones Bone, HumanBodyBones Parent)> EnumerateBoneParentPairs();
|
||||
|
||||
/// <summary>
|
||||
/// * bone 無いときは throw するべし
|
||||
/// * EnumerateBoneParentPairs で事前に有無を確認できる
|
||||
/// </summary>
|
||||
/// <param name="bone"></param>
|
||||
/// <returns></returns>
|
||||
Quaternion GetBoneWorldRotation(HumanBodyBones bone);
|
||||
|
||||
/// <summary>
|
||||
/// * bone 無いときは throw するべし
|
||||
/// * EnumerateBoneParentPairs で事前に有無を確認できる
|
||||
/// </summary>
|
||||
/// <param name="bone"></param>
|
||||
/// <returns></returns>
|
||||
Vector3 GetBoneWorldPosition(HumanBodyBones bone);
|
||||
Quaternion? GetBoneWorldRotation(HumanBodyBones bone);
|
||||
Vector3? GetBoneWorldPosition(HumanBodyBones bone);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user