Optimize eye tracking

This commit is contained in:
CroakFang
2022-11-04 21:01:42 +08:00
parent 472cdb62ed
commit 2e98156a00
5 changed files with 164 additions and 156 deletions
+7 -3
View File
@@ -27,6 +27,7 @@ public class UmaContainer : MonoBehaviour
public GameObject HeadBone;
public GameObject TrackTarget;
public float EyeHeight;
public bool EnableEyeTracking = true;
[Header("Generic")]
public bool IsGeneric = false;
@@ -135,12 +136,15 @@ public class UmaContainer : MonoBehaviour
private void FixedUpdate()
{
if (TrackTarget&&!isAnimatorControl&&!IsMini)
if (TrackTarget&& EnableEyeTracking && !IsMini)
{
var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up*EyeHeight;
var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion);
var deltaRotation = HeadBone.transform.InverseTransformDirection(deltaPos.normalized);
var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.x / 0.86f,-1,1), Mathf.Clamp(deltaRotation.y / 0.66f, -1, 1));//Limited to the angle of view
var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles;
if (deltaRotation.x > 180) deltaRotation.x -= 360;
if (deltaRotation.y > 180) deltaRotation.y -= 360;
var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35,-1,1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view
FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y);
}
+3
View File
@@ -960,6 +960,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
}
else if (clip.name.Contains("face"))
{
@@ -1004,6 +1005,7 @@ public class UmaViewerBuilder : MonoBehaviour
}
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
CurrentUMAContainer.OverrideController["clip_2"].wrapMode = WrapMode.Loop;
CurrentUMAContainer.TrackTarget = PreviewCamera.gameObject;
}
else
{
@@ -1012,6 +1014,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.TrackTarget = Camera.main.gameObject;
SetPreviewCamera(null);
CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime);
+8
View File
@@ -624,6 +624,14 @@ public class UmaViewerUI : MonoBehaviour
}
}
public void SetEyeTrackingEnable(bool isOn)
{
if (Builder.CurrentUMAContainer)
{
Builder.CurrentUMAContainer.EnableEyeTracking = isOn;
}
}
public void ClearCache()
{
PlayerPrefs.DeleteAll();
@@ -305,7 +305,17 @@ namespace Gallop
});
EyeMorphs.ForEach(morph =>
{
morph.weight = morph.locator.transform.localPosition.x * -100;
if (morph == LeftEyeXrange || morph == LeftEyeYrange || morph == RightEyeXrange || morph == RightEyeYrange)
{
if (!Container.EnableEyeTracking)
{
morph.weight = morph.locator.transform.localPosition.x * -100;
}
}
else
{
morph.weight = morph.locator.transform.localPosition.x * -100;
}
});
MouthMorphs.ForEach(morph =>
{