What happened?
In UniVRM10 0.128.3, there are 3 ways to set LookAtInput:
- As part of VRM Animation
|
if (VrmAnimation.LookAt.HasValue) |
|
{ |
|
LookAt.LookAtInput = VrmAnimation.LookAt.Value; |
|
} |
- Throught position of LookAtTarget
SpecifiedTransform
|
if (m_instance.LookAtTargetType == VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform |
|
&& m_instance.LookAtTarget != null) |
|
{ |
|
// Transform 追跡で視線を生成する。 |
|
// 値を上書きします。 |
|
LookAt.LookAtInput = new LookAtInput { WorldPosition = m_instance.LookAtTarget.position }; |
|
} |
- And
SetYawPitchManually()
|
public void SetYawPitchManually(float yaw, float pitch) |
|
{ |
|
LookAtInput = new LookAtInput { YawPitch = new LookAtEyeDirection(yaw, pitch) }; |
|
} |
Since Animation is not the case and YawPitchValue is used historically, SetYawPitchManually() is the way
Patch for DoEye() would look something like this:
void DoEye()
{
var mouse = Input.mousePosition;
var world = mainCam.ScreenToWorldPoint(new Vector3(mouse.x, mouse.y, mainCam.nearClipPlane));
- if (vrm10 && vrmLookAtTarget)
- {
- vrmLookAtTarget.position = world;
- var par = vrmLookAtTarget.parent ?? transform;
- Matrix4x4 mtx = Matrix4x4.TRS(par.position, par.rotation, Vector3.one);
- var (rawYaw, rawPitch) = mtx.CalcYawPitch(world);
- float yaw = Mathf.Clamp(-rawYaw, -eyeYawLimit, eyeYawLimit);
- float pitch = Mathf.Clamp(rawPitch, -eyePitchLimit, eyePitchLimit);
- var currFwd = vrmLookAtTarget.forward;
- var tgtFwd = Quaternion.Euler(-pitch, yaw, 0f) * Vector3.forward;
- var smooth = Vector3.Slerp(currFwd, tgtFwd, Time.deltaTime * eyeSmoothness);
- vrmLookAtTarget.rotation = Quaternion.LookRotation(smooth);
- return;
- }
if (!leftEyeBone || !rightEyeBone || !eyeCenter) return; // VRM1 Expression LookAt operates fine without any eye bones
eyeCenter.position = (leftEyeBone.position + rightEyeBone.position) * 0.5f;
var dir = (world - eyeCenter.position).normalized;
var localDir = eyeCenter.parent.InverseTransformDirection(dir); // Parent of eyeCenter is not always head bone.
// This is not according to VRM standard and ME recommendations, but i would make a check for shared parent for both eye bones
float eyeYaw = Mathf.Clamp(Mathf.Atan2(localDir.x, localDir.z) * Mathf.Rad2Deg, -eyeYawLimit, eyeYawLimit);
float eyePitch = Mathf.Clamp(Mathf.Asin(localDir.y) * Mathf.Rad2Deg, -eyePitchLimit, eyePitchLimit);
+ if (vrm10 && vrmLookAtTarget)
+ {
+ var smoothYaw = Mathf.Lerp(vrm10.Runtime.LookAt.Yaw, eyeYaw, Time.deltaTime * eyeSmoothness);
+ var smoothPitch = Mathf.Lerp(vrm10.Runtime.LookAt.Pitch, eyePitch, Time.deltaTime * eyeSmoothness);
+
+ vrm10.Runtime.LookAt.SetYawPitchManually(smoothYaw, smoothPitch);
+ return;
+ }
var eyeRot = Quaternion.Euler(-eyePitch, eyeYaw, 0f);
leftEyeDriver.localRotation = Quaternion.Slerp(leftEyeDriver.localRotation, eyeRot, Time.deltaTime * eyeSmoothness);
rightEyeDriver.localRotation = Quaternion.Slerp(rightEyeDriver.localRotation, eyeRot, Time.deltaTime * eyeSmoothness);
PS If you have "eyes barely moving", check out Look At settings in VRM1 ScriptableObject.
Formula for Curve*RangeDegree:
|
public float Map(float src) |
|
{ |
|
// https://github.com/vrm-c/UniVRM/issues/2452 |
|
var t = Mathf.Clamp01(src / Mathf.Max(0.001f, CurveXRangeDegree)); |
|
return t * CurveYRangeDegree; |
|
} |
Steps to Reproduce
App Version
2.1.4
Store Edition
GitHub Edition
Confirmation
What happened?
In UniVRM10 0.128.3, there are 3 ways to set LookAtInput:
Mate-Engine/Assets/MATE ENGINE - Packages/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs
Lines 112 to 115 in 2c5ea6b
SpecifiedTransformMate-Engine/Assets/MATE ENGINE - Packages/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs
Lines 127 to 133 in 2c5ea6b
SetYawPitchManually()Mate-Engine/Assets/MATE ENGINE - Packages/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeLookAt.cs
Lines 90 to 93 in 2c5ea6b
Since Animation is not the case and
YawPitchValueis used historically,SetYawPitchManually()is the wayPatch for
DoEye()would look something like this:PS If you have "eyes barely moving", check out Look At settings in VRM1 ScriptableObject.
Formula for Curve*RangeDegree:
Mate-Engine/Assets/MATE ENGINE - Packages/VRM10/Runtime/Components/LookAt/CurveMapper.cs
Lines 40 to 45 in 2c5ea6b
Steps to Reproduce
App Version
2.1.4
Store Edition
GitHub Edition
Confirmation