forked from cgvr/DeltaVR
add separate sprites for animatable mouths for characters, improve animating params
This commit is contained in:
@@ -22,6 +22,7 @@ public abstract class NPCController : MonoBehaviour
|
||||
public float gain = 30f; // multiply RMS to make mouth open larger
|
||||
public float attack = 0.6f; // faster opening
|
||||
public float release = 0.2f; // slower closing
|
||||
public bool inverted = false;
|
||||
|
||||
private float[] rmsCurve;
|
||||
private EventInstance currentVoicelineEvent;
|
||||
@@ -72,8 +73,17 @@ public abstract class NPCController : MonoBehaviour
|
||||
|
||||
float amp = rmsCurve[index] * gain;
|
||||
|
||||
// Normal mapping: louder -> larger scale
|
||||
float mapped = Mathf.Clamp(minScaleY + amp, minScaleY, maxScaleY);
|
||||
|
||||
// Inverted mapping: louder -> smaller scale
|
||||
// Achieve this by mirroring within [min, max]:
|
||||
// invertedTarget = min + (max - (min + amp)) = min + (max - min) - amp
|
||||
// equivalently:
|
||||
float invertedTarget = Mathf.Clamp(minScaleY + (maxScaleY - minScaleY) - (mapped - minScaleY), minScaleY, maxScaleY);
|
||||
float targetY = inverted ? invertedTarget : mapped;
|
||||
|
||||
// attack/release smoothing
|
||||
float targetY = Mathf.Clamp(minScaleY + amp, minScaleY, maxScaleY);
|
||||
if (targetY > smoothed)
|
||||
smoothed = Mathf.Lerp(smoothed, targetY, attack);
|
||||
else
|
||||
@@ -84,21 +94,21 @@ public abstract class NPCController : MonoBehaviour
|
||||
s.y = smoothed;
|
||||
Debug.Log("mouth scale: " + smoothed);
|
||||
mouth.localScale = s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void StopSpeaking()
|
||||
{
|
||||
isSpeaking = false;
|
||||
smoothed = minScaleY;
|
||||
smoothed = inverted ? maxScaleY : minScaleY;
|
||||
|
||||
if (mouth != null)
|
||||
{
|
||||
var scale = mouth.localScale;
|
||||
scale.y = minScaleY;
|
||||
scale.y = smoothed;
|
||||
mouth.localScale = scale;
|
||||
}
|
||||
Debug.Log("mouth scale stopped: " + smoothed);
|
||||
|
||||
currentVoicelineEvent.release();
|
||||
}
|
||||
@@ -148,7 +158,7 @@ public abstract class NPCController : MonoBehaviour
|
||||
|
||||
// Stop mouth on end
|
||||
float voicelineDuration = rmsCurve.Length * FRAME_DURATION;
|
||||
Invoke(nameof(StopSpeaking), voicelineDuration);
|
||||
Invoke(nameof(StopSpeaking), voicelineDuration + 0.1f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user