mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-14 14:59:43 -05:00
UpdateControlRigImplicit
v0.104 仕様の ControlRig 例
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user