1
0
forked from cgvr/DeltaVR

add separate sprites for animatable mouths for characters, improve animating params

This commit is contained in:
2026-02-07 11:37:45 +02:00
parent 1a4e932b1e
commit a682e7245e
20 changed files with 211 additions and 41 deletions

View File

@@ -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);
}