Skip to main content

Drive the MetaHuman Rig Using Viseme Data

This section explains how to import CriLipsMake2's Mpeg4-Visemes Animation Curve File (.csv) as a CurveTable asset and drive the MetaHuman rig by specifying visemes.
(cri/tools/CRILipSyncAlive/samples/MetahumanSample)

Importing as a CurveTable Asset​

This method allows you to import the CSV file output by CriLipsMake2 as a CurveTable asset in Unreal Engine.

First, convert the CSV into a format that Unreal Engine can import.

"""Convert the CSV output by CriLipsMake2 into a format that a UE CurveTable can read.

Usage: python to_curvetable.py csv/A01.csv [output.csv]
"""
import csv
import sys
from pathlib import Path

# Elements to output to the CurveTable
ENABLE_ROWS = ["time","PP","FF","TH","DD","kk","CH","SS","nn","RR","aa","E","ih","oh","ou"]

def main():
if len(sys.argv) < 2:
sys.exit("usage: python to_curvetable.py <input.csv> [output.csv]")

src = Path(sys.argv[1])
dst = Path(sys.argv[2]) if len(sys.argv) > 2 else src.with_name(src.stem + "_curve.csv")

with src.open(newline="", encoding="utf-8") as f:
rows = [r for r in csv.reader(f) if r]
transposed = [list(col) for col in zip(*rows)]

by_name = {row[0]: row for row in transposed}
transposed = [by_name[name] for name in ENABLE_ROWS]

transposed[0][0] = "---" # Represents time

with dst.open("w", newline="", encoding="utf-8") as f:
csv.writer(f).writerows(transposed)

if __name__ == "__main__":
main()
---,0.0000,0.0100,0.0200,0.0300,0.0400,0.0500,0.0600,0.0700,0.0800,0.0900,0.1000,0.1100,0.1200,...
PP,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
FF,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
TH,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
DD,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
kk,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
CH,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
SS,0.0000,0.0000,0.0000,0.0000,0.0111,0.0329,0.0645,0.1047,0.1519,0.2043,0.2597,0.3159,0.3706,...
nn,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
RR,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
aa,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
E,0.3159,0.3706,0.4222,0.4695,0.4998,0.5127,0.5079,0.4860,0.4481,0.3957,0.3403,0.2841,0.2294,...
ih,0.0000,0.0000,0.0000,0.0000,0.0000,0.0012,0.0049,0.0121,0.0237,0.0406,0.0633,0.0921,0.1272,...
oh,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...
ou,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,...

Import the CSV file converted in this way into Unreal Engine as a CurveTable. Setting the curve interpolation to Linear or similar gives a steady appearance even at frame boundaries.

Data table options when importing as a CurveTable (interpolation type: Linear)

Building the Assets to Drive the Rig​

Follow the steps below to build the assets for driving the rig at runtime by specifying visemes.

  1. Create a level sequence and key the facial expression for each viseme on a separate frame
  2. Bake the level sequence into an animation sequence
  3. Create a pose asset from the animation sequence
  4. Create an Animation Blueprint, and drive each pose of the pose asset with viseme data according to the sound being played
  5. Configure the MetaHuman to use the created Animation Blueprint

Adding a MetaHuman to the Level Sequence​

Selecting a MetaHuman from the Add Actor to Sequencer menu in Sequencer

Select the MetaHuman placed in the level.

Controlling the Facial Rig for Each Viseme​

Facial Pose Library templates in the Visemes folder of the control rig poses

Viseme templates are provided as the Facial Pose Library.

A level sequence with facial rig keys set on each frame

For each frame of the level sequence, apply the template that matches the viseme to control the facial rig, and key the resulting pose.

For example, map visemes to templates as follows:

Frame numberVisemeFacial Pose Library
0sil00_Neutral
1PP22_MBP
2FF20_FV
3TH24_Tongue_Th
4DD01_TDS-Ah-
5kk13_KGY_TDS
6CH14_ChJjSh
7SS02_TDS_KGY-Ee-
8nn13_KGY_TDS
9RR17_Rr
10aa07_Aa
11E03_Ee * 0.5 + 07_Aa * 0.5
12ih04_Ih
13oh09_Oh
14ou11_Oo
note

This frame order is also used when naming the poses in the later step "Creating a Pose Asset".

Method without the Facial Pose Library​

Adjust each parameter of the facial rig to create the facial expression of the target viseme.

TH expression created by adjusting the facial rig

Example: TH Expressed with mouth opening, lip stretching, and tongue position.

aa expression created by adjusting the facial rig

Example: aa Expressed with mouth opening and lip stretching.

Baking the Animation Sequence​

Bake Animation Sequence in the right-click menu of the Face track

Select "Bake Animation Sequence" from the right-click menu of the Face track to output the rig movements set in Sequencer as an animation sequence.

Animation sequence options with Export Transforms disabled

Disable "Export Transforms" and bake.

Animation sequence created by baking The animation sequence is created in the specified folder.

Creating a Pose Asset​

Create PoseAsset in the right-click menu of the animation sequence

Select "Create PoseAsset" from the right-click menu of the animation sequence.

This extracts the poses from each frame of the animation sequence.

Viseme names entered in the Pose Names field of the Create PoseAsset dialog

To use the viseme names as pose names, add the viseme names to the OPTIONAL field from top to bottom, in the same order as the visemes registered on each frame of the level sequence.

sil
PP
FF
TH
DD
kk
CH
SS
nn
RR
aa
E
ih
oh
ou

Pose asset with poses registered under viseme names The pose asset is created in the same folder as the animation sequence.

Implementing the Animation Blueprint​

Selecting AnimInstance in the Pick Parent Class dialog

An Animation Blueprint can be selected when creating a Blueprint Class.

Selecting Face_Archetype_Skeleton in the replacement skeleton selection dialog

When the skeleton replacement dialog appears for the first time, select the appropriate skeleton asset.

Processing that obtains viseme data in the Event Graph of the Animation Blueprint In the Event Graph, implement the processing that obtains viseme data according to the playback time of the sound being played.

Processing that applies viseme data to the pose asset in the Anim Graph of the Animation Blueprint In the Anim Graph, implement the processing that applies animation curves from the viseme data to the pose asset.

Configuring the MetaHuman​

Setting Animation Mode and Anim Class on the Face component of the MetaHuman

Change the settings to use an Animation Blueprint, and change the Animation Blueprint to be referenced.