Пример #1
0
 public void OnLipSyncUpdate(LipSyncInfo info)
 {
     foreach (var kv in info.vowels)
     {
         int i = (int)kv.Key;
         blendShapeList[i].blend = kv.Value;
     }
     volume_ = info.volume;
 }
Пример #2
0
        public static void DrawFormants(Profile profile, LipSyncInfo result = null)
        {
            var origColor = Handles.color;

            var area = GUILayoutUtility.GetRect(Screen.width, 300f);

            area = EditorGUI.IndentedRect(area);
            var margin = new Margin(10, 10f, 30f, 40f);
            var range  = new Vector2(1200f, 4000f);

            DrawGrid(
                area,
                Color.white,
                new Color(1f, 1f, 1f, 0.5f),
                margin,
                range,
                new Vector2(6f, 4f));

            if (!profile)
            {
                return;
            }

            float xMin   = area.x + margin.left;
            float xMax   = area.xMax - margin.right;
            float yMin   = area.y + margin.top;
            float yMax   = area.yMax - margin.bottom;
            float width  = xMax - xMin;
            float height = yMax - yMin;

            var colors = new Color[]
            {
                new Color(1f, 0f, 0f, 1f),
                new Color(0f, 1f, 0f, 1f),
                new Color(0f, 0f, 1f, 1f),
                new Color(1f, 1f, 0f, 1f),
                new Color(0f, 1f, 1f, 1f),
            };

            var formants = new FormantPair[]
            {
                profile.formantA,
                profile.formantI,
                profile.formantU,
                profile.formantE,
                profile.formantO,
            };

            var vowelLabels = new string[]
            {
                "A",
                "I",
                "U",
                "E",
                "O",
            };

            float dx = width / range.x;
            float dy = height / range.y;

            for (int i = 0; i < formants.Length; ++i)
            {
                var   f      = formants[i];
                float x      = xMin + dx * f.f1;
                float y      = yMin + (height - dy * f.f2);
                float rx     = profile.maxErrorRange * dx;
                float ry     = profile.maxErrorRange * dy;
                var   center = new Vector3(x, y, 0f);
                var   color  = colors[i];
                Handles.color = color;
                Handles.DrawSolidDisc(center, Vector3.forward, 5f);
                float factor = result != null ? result.vowels[(Vowel)i] : 0f;
                color.a       = Mathf.Lerp(0.15f, 0.5f, factor);
                Handles.color = color;
                DrawEllipse(center, rx, ry, new Rect(xMin, yMin, width, height));
                EditorGUI.LabelField(new Rect(x + 5f, y - 20f, 50f, 20f), vowelLabels[i]);
            }

            if (result != null)
            {
                float x      = xMin + result.formant.f1 * dx;
                float y      = yMin + (height - result.formant.f2 * dy);
                float size   = Mathf.Lerp(2f, 20f, Mathf.Min(result.volume / 0.1f, 1f));
                var   center = new Vector3(x, y, 0f);
                Handles.color = Color.white;
                Handles.DrawWireDisc(center, Vector3.forward, size);
            }

            Handles.color = origColor;
        }