跳到主要内容

将CSV文件转换为资产

关于SDK示例​

本章介绍如何在Unreal Engine中处理CriLipsMake2输出的Mpeg4-Visemes动画曲线文件(.csv)。

示例导入方式驱动对象说明页面
UEProject自定义类型的DataTable资产自定义角色的变形目标本页
MetahumanSampleCurveTable资产MetaHuman的面部绑定通过指定口形素驱动 MetaHuman 绑定

作为自定义类型资产导入​

适用于希望使用游戏应用程序中定义的自定义类型(而非Unreal Engine提供的类型)来处理CSV输出结果的情况。
(cri/tools/CRILipSyncAlive/samples/UEProject)

将CSV文件中的值直接分配给角色模型。 内容浏览器中的DataTable资产

首先,在Source/RealLipsync/Public/SmpUtils.h中以LipsMP4Viseme类型定义DataTable。
在此示例中,仅导入口形素列。

USTRUCT(BlueprintType, Category = "Sample")
struct REALLIPSYNC_API FLipsMP4Viseme
: public FTableRowBase
{
GENERATED_BODY()

public:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float Sil = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float PP = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float FF = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float TH = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float DD = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float KK = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float CH = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float SS = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float NN = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float RR = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float AA = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float E = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float IH = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float OH = 0.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Sample")
float OU = 0.0f;
};

将CriLipsMake2输出的CSV文件作为LipsMP4Viseme导入到项目中。 打开LipsMP4Viseme类型DataTable的界面

为了在Blueprint中使用,在Source/RealLipsync/Private/SmpUtils.cpp中实现查找与当前播放时间相对应的行的GetDataTableValue()。

FLipsMP4Viseme USmpUtils::GetDataTableValue(UDataTable* InDataTable, float InTime)
{
check(IsValid(InDataTable));

if (InTime < 0.0f)
{
return FLipsMP4Viseme();
}

TArray<TPair<float, FName>> TimeNamePairs;
for (const auto& Name : InDataTable->GetRowNames())
{
float Time = FCString::Atof(*Name.ToString());
TimeNamePairs.Add(TPair<float, FName>(Time, Name));
}

TimeNamePairs.Sort([](const TPair<float, FName>& A, const TPair<float, FName>& B) {
return A.Key < B.Key;
});

for (int32 i = 0; i < TimeNamePairs.Num(); ++i)
{
if (InTime <= TimeNamePairs[i].Key)
{
return *InDataTable->FindRow<FLipsMP4Viseme>(TimeNamePairs[i].Value, FString());
}
}

if (TimeNamePairs.Num() > 0)
{
return *InDataTable->FindRow<FLipsMP4Viseme>(TimeNamePairs.Last().Value, FString());
}

return FLipsMP4Viseme();
}

在ModelBP中,将播放音频时获取的DataTable内容分配给角色的口形素变形目标。 在ModelBP的事件图表中为变形目标分配数值的处理