diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index ac9b744ff..585478a26 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -50,6 +50,20 @@ namespace UniVRM10 [SerializeField] public VRM10ObjectLookAt.LookAtTargetTypes LookAtTargetType; + UniHumanoid.Humanoid m_humanoid; + + public UniHumanoid.Humanoid Humanoid + { + get + { + if (m_humanoid == null) + { + m_humanoid = GetComponent(); + } + return m_humanoid; + } + } + Vrm10Runtime m_runtime; /// @@ -111,5 +125,15 @@ namespace UniVRM10 } } } + + public bool TryGetBoneTransform(HumanBodyBones bone, out Transform t) + { + t = Humanoid.GetBoneTransform(bone); + if (t == null) + { + return false; + } + return true; + } } } diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index efaefef26..bf8aa4f41 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -27,14 +27,12 @@ namespace UniVRM10 public Vrm10Runtime(Vrm10Instance target) { m_target = target; - var animator = target.GetComponent(); - if (animator == null) + + if (!target.TryGetBoneTransform(HumanBodyBones.Head, out m_head)) { throw new Exception(); } - - m_head = animator.GetBoneTransform(HumanBodyBones.Head); - m_lookat = new Vrm10RuntimeLookAt(target.Vrm.LookAt, animator, m_head, target.LookAtTargetType, target.Gaze); + m_lookat = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head, target.LookAtTargetType, target.Gaze); m_expression = new Vrm10RuntimeExpression(target, m_lookat, m_lookat.EyeDirectionApplicable); if (m_constraints == null) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeLookAt.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeLookAt.cs index c23e9d14b..b166efc7a 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeLookAt.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeLookAt.cs @@ -5,7 +5,7 @@ using UnityEngine; namespace UniVRM10 { - public class Vrm10RuntimeLookAt: ILookAtEyeDirectionProvider + public class Vrm10RuntimeLookAt : ILookAtEyeDirectionProvider { VRM10ObjectLookAt m_lookat; @@ -85,13 +85,13 @@ namespace UniVRM10 throw new NotImplementedException(); } - internal Vrm10RuntimeLookAt(VRM10ObjectLookAt lookat, Animator animator, Transform head, VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform gaze) + internal Vrm10RuntimeLookAt(VRM10ObjectLookAt lookat, UniHumanoid.Humanoid humanoid, Transform head, VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform gaze) { m_lookat = lookat; m_head = head; - m_leftEye = animator.GetBoneTransform(HumanBodyBones.LeftEye); - m_rightEye = animator.GetBoneTransform(HumanBodyBones.RightEye); + m_leftEye = humanoid.GetBoneTransform(HumanBodyBones.LeftEye); + m_rightEye = humanoid.GetBoneTransform(HumanBodyBones.RightEye); var isRuntimeAsset = true; #if UNITY_EDITOR @@ -122,6 +122,5 @@ namespace UniVRM10 var (yaw, pitch) = GetLookAtYawPitch(m_head, lookAtTargetType, gaze); EyeDirection = new LookAtEyeDirection(yaw, pitch, 0, 0); } - } } diff --git a/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs b/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs index 730db432b..899537002 100644 --- a/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/ModelExporter.cs @@ -45,7 +45,15 @@ namespace UniVRM10 var transform = humanoid.GetBoneTransform(humanBoneType); if (transform != null && Nodes.TryGetValue(transform.gameObject, out VrmLib.Node node)) { - node.HumanoidBone = (VrmLib.HumanoidBones)Enum.Parse(typeof(VrmLib.HumanoidBones), humanBoneType.ToString(), true); + switch (humanBoneType) + { + // https://github.com/vrm-c/vrm-specification/issues/380 + case HumanBodyBones.LeftThumbProximal: node.HumanoidBone = VrmLib.HumanoidBones.leftThumbMetacarpal; break; + case HumanBodyBones.LeftThumbIntermediate: node.HumanoidBone = VrmLib.HumanoidBones.leftThumbProximal; break; + case HumanBodyBones.RightThumbProximal: node.HumanoidBone = VrmLib.HumanoidBones.rightThumbMetacarpal; break; + case HumanBodyBones.RightThumbIntermediate: node.HumanoidBone = VrmLib.HumanoidBones.rightThumbProximal; break; + default: node.HumanoidBone = (VrmLib.HumanoidBones)Enum.Parse(typeof(VrmLib.HumanoidBones), humanBoneType.ToString(), true); break; + } } } } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 234dcacd1..1fab7d277 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -722,9 +722,14 @@ namespace UniVRM10 public static HumanBodyBones ToUnity(VrmLib.HumanoidBones bone) { - if (bone == VrmLib.HumanoidBones.unknown) + switch (bone) { - return HumanBodyBones.LastBone; + // https://github.com/vrm-c/vrm-specification/issues/380 + case VrmLib.HumanoidBones.unknown: return HumanBodyBones.LastBone; + case VrmLib.HumanoidBones.leftThumbMetacarpal: return HumanBodyBones.LeftThumbProximal; + case VrmLib.HumanoidBones.leftThumbProximal: return HumanBodyBones.LeftThumbIntermediate; + case VrmLib.HumanoidBones.rightThumbMetacarpal: return HumanBodyBones.RightThumbProximal; + case VrmLib.HumanoidBones.rightThumbProximal: return HumanBodyBones.RightThumbIntermediate; } return VrmLib.EnumUtil.Cast(bone); }