From 6e377b05439b716b15a08445b6f69ebf2093bb9a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 3 Oct 2022 18:06:40 +0900 Subject: [PATCH] UpdateControlRigImplicit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v0.104 仕様の ControlRig 例 --- .../VRM10_Samples/VRM10Viewer/VRM10Loaded.cs | 71 ++++++++++++++----- .../VRM10Viewer/VRM10ViewerUI.cs | 9 ++- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs index dae56a379..05824727f 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs @@ -88,7 +88,11 @@ namespace UniVRM10.VRM10Viewer GameObject.Destroy(m_instance.gameObject); } - public void UpdatePose(bool useBvh, Animator bvhAnimator) + /// + /// from v0.103 + /// + /// + 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; } } } + + /// + /// from v0.104 + /// + /// + public void UpdateControlRigImplicit(Animator src) + { + var dst = m_controller.GetComponent(); + + foreach (HumanBodyBones bone in CachedEnum.GetValues()) + { + 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(); + } } -} \ No newline at end of file +} diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index d56a40a21..6bc7142c1 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -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(); + } } }