From 4f611997f3d834f95e3d939ffb813ceead7b655a Mon Sep 17 00:00:00 2001 From: Emiliana <38952746+emilianavt@users.noreply.github.com> Date: Sun, 8 Mar 2020 18:15:43 +0100 Subject: [PATCH] Fudging thresholds when the head turns left or right is cheating, but it seems to work well. --- Examples/OpenSeeVRMDriver.cs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/Examples/OpenSeeVRMDriver.cs b/Examples/OpenSeeVRMDriver.cs index db5407b..622573f 100644 --- a/Examples/OpenSeeVRMDriver.cs +++ b/Examples/OpenSeeVRMDriver.cs @@ -124,6 +124,9 @@ public class OpenSeeVRMDriver : MonoBehaviour { private OpenSeeVRMExpression currentExpression = null; private OpenSee.OpenSee.OpenSeeData openSeeData = null; + private float turnLeftBoundaryAngle = -30f; + private float turnRightBoundaryAngle = 20f; + private double lastGaze = 0f; private float lastLookUpDown = 0f; private float lastLookLeftRight = 0f; @@ -227,13 +230,20 @@ void ApplyMouthShape() { float open = openSeeData.features.MouthOpen; float wide = openSeeData.features.MouthWide; float[] mouthStates = new float[]{0f, 0f, 0f, 0f, 0f}; + float stabilizer = mouthStabilizer; + float stabilizerWide = mouthStabilizerWide; + + if (openSeeData.rawEuler.y < turnLeftBoundaryAngle || openSeeData.rawEuler.y > turnRightBoundaryAngle) { + stabilizer *= 2.5f; + stabilizerWide *= 2.5f; + } do { if (mouthUseSquelch && audioVolume < mouthSquelch) break; - if (open < mouthStabilizer && Mathf.Abs(wide) < mouthStabilizer) + if (open < stabilizer && Mathf.Abs(wide) < stabilizer) break; - if (wide > mouthStabilizer && open < mouthStabilizerWide) + if (wide > stabilizer && open < stabilizerWide) break; if (open > 0.5f) { // O @@ -242,7 +252,7 @@ void ApplyMouthShape() { // A mouthStates[0] = open * 1f; } - if (wide >= 0f) { + if (wide >= 0f && open > stabilizer * 0.5f) { if (wide > 0.5f) { // I mouthStates[1] = wide; @@ -250,7 +260,7 @@ void ApplyMouthShape() { // E mouthStates[3] = wide * 1f; } - } else if (wide < Mathf.Clamp(mouthStabilizerWide * 1.5f, 0f, 0.8f)) { + } else if (wide < Mathf.Clamp(stabilizerWide * 1.5f, 0f, 0.8f) && open > stabilizer) { // U mouthStates[2] = -wide; } @@ -523,20 +533,29 @@ void BlinkEyes() { if (openSeeData != null && lastBlink < openSeeData.time) { lastBlink = openSeeData.time; + float openThreshold = eyeOpenedThreshold; - if (openSeeData.rightEyeOpen > eyeOpenedThreshold) + if (openSeeData.rawEuler.y < turnLeftBoundaryAngle || openSeeData.rawEuler.y > turnRightBoundaryAngle) + openThreshold = Mathf.Lerp(openThreshold, eyeClosedThreshold, 0.4f); + + if (openSeeData.rightEyeOpen > openThreshold) right = 0f; else if (openSeeData.rightEyeOpen < eyeClosedThreshold) right = 1f; else - right = 1f - (openSeeData.rightEyeOpen - eyeClosedThreshold) / (eyeOpenedThreshold - eyeClosedThreshold); + right = 1f - (openSeeData.rightEyeOpen - eyeClosedThreshold) / (openThreshold - eyeClosedThreshold); - if (openSeeData.leftEyeOpen > eyeOpenedThreshold) + if (openSeeData.leftEyeOpen > openThreshold) left = 0f; else if (openSeeData.leftEyeOpen < eyeClosedThreshold) left = 1f; else - left = 1f - (openSeeData.leftEyeOpen - eyeClosedThreshold) / (eyeOpenedThreshold - eyeClosedThreshold); + left = 1f - (openSeeData.leftEyeOpen - eyeClosedThreshold) / (openThreshold - eyeClosedThreshold); + + if (openSeeData.rawEuler.y < turnLeftBoundaryAngle) + left = right; + if (openSeeData.rawEuler.y > turnRightBoundaryAngle) + right = left; lastBlinkLeft = currentBlinkLeft; lastBlinkRight = currentBlinkRight;