Skip to content
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
2 changes: 1 addition & 1 deletion Assets/Scripts/Animator/FaceLandmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FaceLandmarks {
public float MouthAspectRatio { get; set; }
public EyeShape LeftEyeShape { get; set; }
public EyeShape RightEyeShape { get; set; }
public Vector3 FaceRotation { get; set; }
public Quaternion FaceRotation { get; set; }
public MouthShape MouthShape {
get {
if (MouthAspectRatio < 0.1) {
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/Animator/FaceLandmarksRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ public FaceLandmarks recognize(NormalizedLandmarkList faceLandmarkList) {
solvePnP(_screenWidth, _screenHeight, _face3DPoints, pnpArray, null, null, _rotationVector,
_translationVector, useExtrinsicGuess);

var roll = (float)(-Degree(_rotationVector[0]));
var yaw = (float)(-Degree(_rotationVector[1]) + 180);
var pitch = (float)(-Degree(_rotationVector[2]));
faceLandmarks.FaceRotation = new Vector3(yaw, roll, pitch);
Vector3 axis = new Vector3(_rotationVector[0], _rotationVector[1], _rotationVector[2]);
float theta = (float)(axis.magnitude * 180 / Math.PI);
faceLandmarks.FaceRotation = Quaternion.AngleAxis(theta, axis);

faceLandmarks.MouthAspectRatio = ComputeMouth(faceMesh);
var leftEyeAspectRatio = ComputeEye(faceMesh, _leftEyeIndex);
Expand Down
9 changes: 2 additions & 7 deletions Assets/Scripts/Animator/UpperBodyAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class UpperBodyAnimator : MonoBehaviour {
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 @@ -98,7 +99,7 @@ private void setupJoints(Animator anim) {
void LateUpdate() {
if (_faceLandmarkList != null) {
FaceLandmarks faceLandmarks = _faceLandmarksRecognizer.recognize(_faceLandmarkList);
_neck.localEulerAngles = ClampFaceRotation(faceLandmarks.FaceRotation);
_neck.rotation = faceLandmarks.FaceRotation * _neckInitRotation;
SetMouth(faceLandmarks.MouthAspectRatio);
SetEye(faceLandmarks.LeftEyeShape == EyeShape.Close &&
faceLandmarks.RightEyeShape == EyeShape.Close);
Expand All @@ -112,12 +113,6 @@ void LateUpdate() {
}
}

private Vector3 ClampFaceRotation(Vector3 rotation) {
return new Vector3(rotation.x, // Do not clamp x
Mathf.Clamp(rotation.y, -MaxRotationThreshold, MaxRotationThreshold),
Mathf.Clamp(rotation.z, -MaxRotationThreshold, MaxRotationThreshold));
}

private void SetMouth(float ratio) {
_mouthMeshRenderer.SetBlendShapeWeight(2, ratio * 100);
}
Expand Down