UpdateControlRigImplicit

v0.104 仕様の ControlRig 例
This commit is contained in:
ousttrue
2022-10-03 18:06:40 +09:00
parent a8d5704a0f
commit 6e377b0543
2 changed files with 63 additions and 17 deletions

View File

@@ -88,7 +88,11 @@ namespace UniVRM10.VRM10Viewer
GameObject.Destroy(m_instance.gameObject);
}
public void UpdatePose(bool useBvh, Animator bvhAnimator)
/// <summary>
/// from v0.103
/// </summary>
/// <param name="src"></param>
public void UpdateControlRigExplicit(Animator src)
{
var controlRig = m_controller.Runtime.ControlRig;
@@ -105,25 +109,60 @@ namespace UniVRM10.VRM10Viewer
continue;
}
if (useBvh && bvhAnimator != null)
var bvhBone = src.GetBoneTransform(bone);
if (bvhBone != null)
{
var bvhBone = bvhAnimator.GetBoneTransform(bone);
if (bvhBone != null)
{
// set normalized pose
controlRigBone.localRotation = bvhBone.localRotation;
}
if (bone == HumanBodyBones.Hips)
{
controlRigBone.localPosition = bvhBone.localPosition * controlRig.InitialHipsHeight;
}
// set normalized pose
controlRigBone.localRotation = bvhBone.localRotation;
}
else
if (bone == HumanBodyBones.Hips)
{
controlRig.EnforceTPose();
controlRigBone.localPosition = bvhBone.localPosition * controlRig.InitialHipsHeight;
}
}
}
/// <summary>
/// from v0.104
/// </summary>
/// <param name="src"></param>
public void UpdateControlRigImplicit(Animator src)
{
var dst = m_controller.GetComponent<Animator>();
foreach (HumanBodyBones bone in CachedEnum.GetValues<HumanBodyBones>())
{
if (bone == HumanBodyBones.LastBone)
{
continue;
}
var boneTransform = dst.GetBoneTransform(bone);
if (boneTransform == null)
{
continue;
}
var bvhBone = src.GetBoneTransform(bone);
if (bvhBone != null)
{
// set normalized pose
boneTransform.localRotation = bvhBone.localRotation;
}
if (bone == HumanBodyBones.Hips)
{
// TODO: hips position scaling ?
boneTransform.localPosition = bvhBone.localPosition;
}
}
}
public void TPoseControlRig()
{
var controlRig = m_controller.Runtime.ControlRig;
controlRig.EnforceTPose();
}
}
}
}

View File

@@ -250,7 +250,14 @@ namespace UniVRM10.VRM10Viewer
if (m_loaded != null)
{
m_loaded.UpdatePose(m_ui.IsBvhEnabled, m_src);
if (m_ui.IsBvhEnabled && m_src != null)
{
m_loaded.UpdateControlRigImplicit(m_src);
}
else
{
m_loaded.TPoseControlRig();
}
}
}