Skip to content

Commit

Permalink
Add Avatoranimator script for seedV modal (#45)
Browse files Browse the repository at this point in the history
* Add Avatoranimator script for seedV modal

* Fix some coding style error

* Fixed coding style error

* Fix coding style error

* Fix coding style error

* Fix coding style error

* Fixed some review recommend

* Extract FaceLandmarks into a param to SetMouth

* Update method param and remove code redundancy

* Untrack unneeded file

* Fix spelling.

* Untrack AvatarAnimator.cs

Co-authored-by: sunzhifeng <[email protected]>
Co-authored-by: henryouly <[email protected]>
  • Loading branch information
3 people authored Jun 21, 2022
1 parent c3b0f7c commit e92468e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Assets/Scripts/Animator/UpperBodyAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class UpperBodyAnimator : MonoBehaviour {
public float MaxRotationThreshold = 40f;
[Tooltip("Screen width used as to scale the recognized normalized landmarks.")]
public float ScreenWidth = 1920;
public Quaternion _neckInitRotation = Quaternion.Euler(0, -90, -90);
[Tooltip("Screen height used as to scale the recognized normalized landmarks.")]
public float ScreenHeight = 1080;
private const string MthDefConst = "MTH_DEF";
private const string EyeDefConst = "EYE_DEF";
private const string ElDefConst = "EL_DEF";
private static readonly Quaternion _neckInitRotation = Quaternion.Euler(0, -90, -90);
/// <summary>The neck joint to control head rotation.</summary>
private Transform _neck;
/// <summary>Face landmark recognizer.</summary>
Expand Down Expand Up @@ -100,7 +100,7 @@ void LateUpdate() {
if (_faceLandmarkList != null) {
FaceLandmarks faceLandmarks = _faceLandmarksRecognizer.recognize(_faceLandmarkList);
_neck.rotation = faceLandmarks.FaceRotation * _neckInitRotation;
SetMouth(faceLandmarks.MouthAspectRatio);
SetMouth(faceLandmarks);
SetEye(faceLandmarks.LeftEyeShape == EyeShape.Close &&
faceLandmarks.RightEyeShape == EyeShape.Close);
}
Expand All @@ -113,11 +113,11 @@ void LateUpdate() {
}
}

private void SetMouth(float ratio) {
_mouthMeshRenderer.SetBlendShapeWeight(2, ratio * 100);
public virtual void SetMouth(FaceLandmarks faceLandmarks) {
_mouthMeshRenderer.SetBlendShapeWeight(2, faceLandmarks.MouthAspectRatio * 100);
}

private void SetEye(bool close) {
public virtual void SetEye(bool close) {
if (close) {
_eyeMeshRenderer.SetBlendShapeWeight(6, 100);
_elMeshRenderer.SetBlendShapeWeight(6, 100);
Expand Down

0 comments on commit e92468e

Please sign in to comment.