mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-20 09:34:42 -05:00
LookAtInput を導入。LookAt.Process を整理。値の取得 => 位置ベースの場合に角度に解決 の2ステップ。
obsolete 削除
This commit is contained in:
15
Assets/VRM10/Runtime/Components/LookAt/LookAtInput.cs
Normal file
15
Assets/VRM10/Runtime/Components/LookAt/LookAtInput.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
/// <summary>
|
||||
/// LookAt を具体的な値に解決する前の入力値
|
||||
/// この値を元に LookAtEyeDirection を生成し、
|
||||
/// LookAtEyeDirection を Bone もしくは MorphTarget に対して適用する。
|
||||
/// </summary>
|
||||
public struct LookAtInput
|
||||
{
|
||||
public LookAtEyeDirection? YawPitch;
|
||||
public Vector3? WorldPosition;
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Runtime/Components/LookAt/LookAtInput.cs.meta
Normal file
11
Assets/VRM10/Runtime/Components/LookAt/LookAtInput.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f7a52869fd45b2439bce28499c3f8dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -202,21 +202,6 @@ namespace UniVRM10
|
||||
{
|
||||
Expression.SetWeight(k, v());
|
||||
}
|
||||
|
||||
// TODO: look at target
|
||||
//
|
||||
// この Frame の LookAt 値をアップデート
|
||||
//
|
||||
// struct LookAtValue
|
||||
// {
|
||||
// LookAtTargetTypes;
|
||||
//
|
||||
// (float, float) YawPitch; // 一番明確
|
||||
// Vector3 GazePosition; // 座標系?
|
||||
// Transform GazeTarget; // 解決順のため遅延させる意図があるか
|
||||
// }
|
||||
//
|
||||
// あとで、LookAt.Process の引き数にわたす
|
||||
}
|
||||
|
||||
// 2. Control Rig
|
||||
@@ -229,10 +214,37 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
// 4. Gaze control
|
||||
LookAt.Process(m_instance.LookAtTargetType, m_instance.LookAtTarget);
|
||||
LookAtInput lookAtInput = default;
|
||||
if (VrmAnimation != null && VrmAnimation.LookAt.HasValue)
|
||||
{
|
||||
// VrmAnimation から LookAt を供給される
|
||||
lookAtInput = VrmAnimation.LookAt.Value;
|
||||
}
|
||||
else if (m_instance.LookAtTargetType == VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform
|
||||
&& m_instance.LookAtTarget != null)
|
||||
{
|
||||
// Transform 追跡で 視線を計算する
|
||||
lookAtInput = new LookAtInput { WorldPosition = m_instance.LookAtTarget.position };
|
||||
}
|
||||
else
|
||||
{
|
||||
// 事前に LookAt.SetYawPitchManually を呼び出し済みであることが期待される
|
||||
lookAtInput = new LookAtInput { YawPitch = new LookAtEyeDirection(LookAt.Yaw, LookAt.Pitch, 0, 0) };
|
||||
}
|
||||
|
||||
LookAtEyeDirection eyeDirection = default;
|
||||
if (lookAtInput.YawPitch.HasValue)
|
||||
{
|
||||
eyeDirection = lookAtInput.YawPitch.Value;
|
||||
}
|
||||
else if (lookAtInput.WorldPosition.HasValue)
|
||||
{
|
||||
eyeDirection = LookAt.Process(lookAtInput.WorldPosition.Value);
|
||||
}
|
||||
|
||||
// 5. Apply Expression
|
||||
Expression.Process(LookAt.EyeDirection);
|
||||
// LookAt の角度制限などはこちらで処理されます。
|
||||
Expression.Process(eyeDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,22 @@ using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public sealed class Vrm10RuntimeLookAt : ILookAtEyeDirectionProvider
|
||||
public sealed class Vrm10RuntimeLookAt
|
||||
{
|
||||
public float Yaw { get; private set; }
|
||||
public float Pitch { get; private set; }
|
||||
/// <summary>
|
||||
/// Yaw/Pitch 値を直接設定します。
|
||||
/// LookAtTargetTypes が SpecifiedTransform の場合、ここで設定しても値は上書きされます。
|
||||
/// </summary>
|
||||
/// <param name="yaw">Headボーンのforwardに対するyaw角(度)</param>
|
||||
/// <param name="pitch">Headボーンのforwardに対するpitch角(度)</param>
|
||||
public void SetYawPitchManually(float yaw, float pitch)
|
||||
{
|
||||
Yaw = yaw;
|
||||
Pitch = pitch;
|
||||
}
|
||||
|
||||
private readonly VRM10ObjectLookAt _lookAt;
|
||||
private readonly Transform _head;
|
||||
private readonly Vector3 _lookAtOriginTransformLocalPosition;
|
||||
@@ -13,8 +27,6 @@ namespace UniVRM10
|
||||
|
||||
internal ILookAtEyeDirectionApplicable EyeDirectionApplicable { get; }
|
||||
|
||||
public float Yaw { get; private set; }
|
||||
public float Pitch { get; private set; }
|
||||
public LookAtEyeDirection EyeDirection { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -52,39 +64,12 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
internal void Process(VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform lookAtTarget)
|
||||
internal LookAtEyeDirection Process(Vector3 worldPosition)
|
||||
{
|
||||
LookAtOriginTransform.localPosition = _lookAtOriginTransformLocalPosition;
|
||||
LookAtOriginTransform.localRotation = _lookAtOriginTransformLocalRotation;
|
||||
|
||||
switch (lookAtTargetType)
|
||||
{
|
||||
case VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform:
|
||||
// NOTE: 指定された Transform の位置を向くように Yaw/Pitch を計算して適用する
|
||||
if (lookAtTarget != null)
|
||||
{
|
||||
var value = CalculateYawPitchFromLookAtPosition(lookAtTarget.position);
|
||||
SetYawPitchManually(value.Yaw, value.Pitch);
|
||||
}
|
||||
break;
|
||||
case VRM10ObjectLookAt.LookAtTargetTypes.YawPitchValue:
|
||||
// NOTE: 直接 Set された Yaw/Pitch を使って計算する
|
||||
break;
|
||||
}
|
||||
|
||||
EyeDirection = new LookAtEyeDirection(Yaw, Pitch, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Yaw/Pitch 値を直接設定します。
|
||||
/// LookAtTargetTypes が SpecifiedTransform の場合、ここで設定しても値は上書きされます。
|
||||
/// </summary>
|
||||
/// <param name="yaw">Headボーンのforwardに対するyaw角(度)</param>
|
||||
/// <param name="pitch">Headボーンのforwardに対するpitch角(度)</param>
|
||||
public void SetYawPitchManually(float yaw, float pitch)
|
||||
{
|
||||
Yaw = yaw;
|
||||
Pitch = pitch;
|
||||
var (yaw, pitch) = CalculateYawPitchFromLookAtPosition(worldPosition);
|
||||
return new LookAtEyeDirection(yaw, pitch, 0, 0);
|
||||
}
|
||||
|
||||
public (float Yaw, float Pitch) CalculateYawPitchFromLookAtPosition(Vector3 lookAtWorldPosition)
|
||||
@@ -104,36 +89,5 @@ namespace UniVRM10
|
||||
|
||||
return lookAtOrigin;
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use " + nameof(LookAtOriginTransform))]
|
||||
public Transform GetLookAtOrigin(Transform head)
|
||||
{
|
||||
return LookAtOriginTransform;
|
||||
}
|
||||
|
||||
[Obsolete("Use " + nameof(SetYawPitchManually))]
|
||||
public void SetLookAtYawPitch(float yaw, float pitch)
|
||||
{
|
||||
SetYawPitchManually(yaw, pitch);
|
||||
}
|
||||
|
||||
[Obsolete("Use " + nameof(Yaw) + " & " + nameof(Pitch))]
|
||||
public (float, float) GetLookAtYawPitch(
|
||||
Transform head,
|
||||
VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType,
|
||||
Transform gaze)
|
||||
{
|
||||
switch (lookAtTargetType)
|
||||
{
|
||||
case VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform:
|
||||
return CalculateYawPitchFromLookAtPosition(gaze.position);
|
||||
case VRM10ObjectLookAt.LookAtTargetTypes.YawPitchValue:
|
||||
return (Yaw, Pitch);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(lookAtTargetType), lookAtTargetType, null);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
@@ -8,5 +9,6 @@ namespace UniVRM10
|
||||
(INormalizedPoseProvider, ITPoseProvider) ControlRig { get; }
|
||||
IReadOnlyDictionary<ExpressionKey, Func<float>> ExpressionMap { get; }
|
||||
public void ShowBoxMan(bool enable);
|
||||
LookAtInput? LookAt { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace UniVRM10
|
||||
readonly Dictionary<ExpressionKey, Action<float>> _ExpressionSetterMap = new();
|
||||
public IReadOnlyDictionary<ExpressionKey, Action<float>> ExpressionSetterMap => _ExpressionSetterMap;
|
||||
|
||||
public LookAtInput? LookAt { get; set; }
|
||||
|
||||
void InitializeExpression(ExpressionKey key, Func<float> getter, Action<float> setter)
|
||||
{
|
||||
_ExpressionGetterMap.Add(key, getter);
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace UniVRM10.VRM10Viewer
|
||||
IDictionary<ExpressionKey, Func<float>> _ExpressionMap = new Dictionary<ExpressionKey, Func<float>>();
|
||||
public IReadOnlyDictionary<ExpressionKey, Func<float>> ExpressionMap => (IReadOnlyDictionary<ExpressionKey, Func<float>>)_ExpressionMap;
|
||||
|
||||
public LookAtInput? LookAt { get; set; }
|
||||
|
||||
public BvhMotion(UniHumanoid.BvhImporterContext context)
|
||||
{
|
||||
m_context = context;
|
||||
|
||||
Reference in New Issue
Block a user