Animator じゃなくて Vrm10Instance から bone を得る

This commit is contained in:
ousttrue
2022-06-24 18:10:42 +09:00
parent 1ddddad6ee
commit f19389c03a
5 changed files with 47 additions and 13 deletions

View File

@@ -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<UniHumanoid.Humanoid>();
}
return m_humanoid;
}
}
Vrm10Runtime m_runtime;
/// <summary>
@@ -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;
}
}
}

View File

@@ -27,14 +27,12 @@ namespace UniVRM10
public Vrm10Runtime(Vrm10Instance target)
{
m_target = target;
var animator = target.GetComponent<Animator>();
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)

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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<HumanBodyBones>(bone);
}