8000 cherry-pick `Refactoring about Vrm10 LookAtRuntime` by Santarh · Pull Request #9 · virtual-cast/UniVRM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cherry-pick Refactoring about Vrm10 LookAtRuntime #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

< 8000 p class="mt-4 color-fg-muted text-center">By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions Assets/VRM10/Editor/EditorTool/VRM10LookAtEditorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ public override void OnToolGUI(EditorWindow window)
{
EditorGUI.BeginChangeCheck();

var worldOffset = head.localToWorldMatrix.MultiplyPoint(root.Vrm.LookAt.OffsetFromHead);
worldOffset = Handles.PositionHandle(worldOffset, head.rotation);
var eyeWorldPosition = head.localToWorldMatrix.MultiplyPoint(root.Vrm.LookAt.OffsetFromHead);
eyeWorldPosition = Handles.PositionHandle(eyeWorldPosition, head.rotation);

Handles.DrawDottedLine(head.position, worldOffset, 5);
Handles.DrawDottedLine(head.position, eyeWorldPosition, 5);
Handles.SphereHandleCap(0, head.position, Quaternion.identity, 0.02f, Event.current.type);
Handles.SphereHandleCap(0, worldOffset, Quaternion.identity, 0.02f, Event.current.type);
Handles.SphereHandleCap(0, eyeWorldPosition, Quaternion.identity, 0.02f, Event.current.type);

if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(root.Vrm, "LookAt.OffsetFromHead");

root.Vrm.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(worldOffset);
root.Vrm.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(eyeWorldPosition);
}
}

if (Application.isPlaying)
{
OnSceneGUILookAt(root.Vrm.LookAt, root.Runtime.LookAt, head, root.LookAtTargetType, root.Gaze);
OnSceneGUILookAt(root.Vrm.LookAt, root.Runtime.LookAt, root.LookAtTargetType, root.LookAtTarget);
}
else
{
Expand Down Expand Up @@ -125,28 +125,27 @@ static void DrawMatrix(Matrix4x4 m, float size)

const float RADIUS = 0.5f;

static void OnSceneGUILookAt(VRM10ObjectLookAt lookAt, Vrm10RuntimeLookAt runtime, Transform head, VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform gaze)
static void OnSceneGUILookAt(VRM10ObjectLookAt lookAt, Vrm10RuntimeLookAt runtime, VRM10ObjectLookAt.LookAtTargetTypes lookAtTargetType, Transform lookAtTarget)
{
if (head == null) return;

if (gaze != null)
if (lookAtTargetType == VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform && lookAtTarget != null)
{
{
EditorGUI.BeginChangeCheck();
var newTargetPosition = Handles.PositionHandle(gaze.position, Quaternion.identity);
var newTargetPosition = Handles.PositionHandle(lookAtTarget.position, Quaternion.identity);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(gaze, "Change Look At Target Position");
gaze.position = newTargetPosition;
Undo.RecordObject(lookAtTarget, "Change Look At Target Position");
lookAtTarget.position = newTargetPosition;
}
}

Handles.color = new Color(1, 1, 1, 0.6f);
Handles.DrawDottedLine(runtime.GetLookAtOrigin(head).position, gaze.position, 4.0f);
Handles.DrawDottedLine(runtime.LookAtOriginTransform.position, lookAtTarget.position, 4.0f);
}

var (yaw, pitch) = runtime.GetLookAtYawPitch(head, lookAtTargetType, gaze);
var lookAtOriginMatrix = runtime.GetLookAtOrigin(head).localToWorldMatrix;
var yaw = runtime.Yaw;
var pitch = runtime.Pitch;
var lookAtOriginMatrix = runtime.LookAtOriginTransform.localToWorldMatrix;
Handles.matrix = lookAtOriginMatrix;
var p = lookAt.OffsetFromHead;
Handles.Label(Vector3.zero,
Expand Down
5 changes: 5 additions & 0 deletions Assets/VRM10/Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#if UNITY_EDITOR
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("VRM10.Tests")]
#endif
11 changes: 11 additions & 0 deletions Assets/VRM10/Runtime/AssemblyInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public readonly struct LookAtEyeDirection
public float LeftPitch { get; }

/// <summary>
/// NOTE: 何故か使われていない
/// Yaw of RightEye
/// </summary>
public float RightYaw { get; }

/// <summary>
/// NOTE: 何故か使われていない
/// Pitch of RightEye
/// </summary>
public float RightPitch { get; }
Expand Down
16 changes: 11 additions & 5 deletions Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectLookAt.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using UnityEngine;
using UniGLTF.Extensions.VRMC_vrm;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace UniVRM10
{
Expand All @@ -12,8 +9,17 @@ public class VRM10ObjectLookAt
{
public enum LookAtTargetTypes
{
CalcYawPitchToGaze,
SetYawPitch,
/// <summary>
/// Vrm10Instance に設定した Transform を見ます.
/// </summary>
SpecifiedTransform = 0,
/// <summary>
/// Vrm10RuntimeLookAt に設定した Yaw/Pitch 値に従います.
/// </summary>
YawPitchValue = 1,

[Obsolete] CalcYawPitchToGaze = 0,
[Obsolete] SetYawPitch = 1,
}

[SerializeField]
Expand Down
38 changes: 25 additions & 13 deletions Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;


namespace UniVRM10
Expand Down Expand Up @@ -43,11 +45,20 @@ public enum UpdateTypes
public bool DrawLookAtGizmo = true;

/// <summay>
/// LookAtTargetTypes.CalcYawPitchToGaze時の注視点
/// The model looks at position of the Transform specified in this field.
/// That behaviour is available only when LookAtTargetType is SpecifiedTransform.
///
/// モデルはここで指定した Transform の位置の方向に目を向けます。
/// LookAtTargetType を SpecifiedTransform に設定したときのみ有効です。
/// </summary>
[SerializeField]
public Transform Gaze;
[SerializeField, FormerlySerializedAs("Gaze")]
public Transform LookAtTarget;

/// <summary>
/// Specify "LookAt" behaviour at runtime.
///
/// 実行時の目の動かし方を指定します。
/// </summary>
[SerializeField]
public VRM10ObjectLookAt.LookAtTargetTypes LookAtTargetType;

Expand Down Expand Up @@ -110,15 +121,7 @@ void Start()

// cause new Vrm10Runtime.
// init LookAt init rotation.
var runtime = Runtime;

if (LookAtTargetType == VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze)
{
if (Gaze == null)
{
LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.SetYawPitch;
}
}
var _ = Runtime;
}

private void Update()
Expand Down Expand Up @@ -165,6 +168,15 @@ public bool TryGetBoneTransform(HumanBodyBones bone, out Transform t)
return true;
}

#region Obsolete

[Obsolete]
public Transform Gaze
{
get => LookAtTarget;
set => LookAtTarget = value;
}

#endregion
}
}
4 changes: 2 additions & 2 deletions Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Vrm10Runtime(Vrm10Instance target, IReadOnlyDictionary<HumanBodyBones, Qu
ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform, controlRigInitialRotations);
}
Constraints = target.GetComponentsInChildren<IVrm10Constraint>();
LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head, target.LookAtTargetType, target.Gaze);
LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head);
Expression = new Vrm10RuntimeExpression(target, LookAt, LookAt.EyeDirectionApplicable);

var instance = target.GetComponent<RuntimeGltfInstance>();
Expand Down Expand Up @@ -191,7 +191,7 @@ public void Process()
}

// 3. Gaze control
LookAt.Process(m_target.LookAtTargetType, m_target.Gaze);
LookAt.Process(m_target.LookAtTargetType, m_target.LookAtTarget);

// 4. Expression
4BEE Expression.Process();
Expand Down
Loading
0