CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriAtom]从脚本生成LipSync插件进行口型同步

示例内容

概述

在执行应用程序时生成用于口型同步的组件,
在角色模型设置的同时进行实时口型同步。
cri4u_samples_criatom_expansion_lipsync_scene02_main.png

操作方法


场景信息


中间件 ADX LipSync(CRI Lips), CRI ADX (CRI Atom)
示例 Expansion示例
存储位置 /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/expansion/LipSync
场景文件 Scene_02_LipSync_ScriptAddComponent.unity
ACF文件 /CRIWARE/SDK/unity/samples/UnityProject/Assets/StreamingAssets/ADXLipSync/ForADXLipSyncSample.acf
ACB文件 /CRIWARE/SDK/unity/samples/UnityProject/Assets/StreamingAssets/ADXLipSync/ForADXLipSyncSample.acb


程序说明

首先在 Start() 函数内使用 AddComponent() 添加 CriLipsDeformerForAtomSource 组件
进行LipSync程度库的初始化和口形解析器的生成。
private void Start()
{
this.criLipsDeformer = this.gameObject.AddComponent<CriLipsDeformerForAtomSource>();
}
根据角色模型持有的各变形目标信息生成 CriWare.CriLipsMorphBlendShapeWidthHeight 对象,
注册至 CriWare.CriLipsDeformerForAtomSource::LipsMorph
此时,需要将变形目标名通过 GetBlendShapeIndex() 等
转换为索引值并传递给 CriWare.CriLipsMorphBlendShapeWidthHeight::lipHeightIndex
CriLipsMorphBlendShapeWidthHeight lipsMorph = new CriLipsMorphBlendShapeWidthHeight();
lipsMorph.Target = skinnedMeshRenderer;
// Set morph target index to CriLipsMorphBlendShapeWidthHeight.
lipsMorph.lipHeightIndex
= skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("blendShape.LipHeightOpen");
lipsMorph.lipWidthOpenIndex
= skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("blendShape.LipWidthOpen");
lipsMorph.lipWidthCloseIndex
= skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("blendShape.LipWidthClose");
lipsMorph.tongueUpIndex
= skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex("blendShape.Tongue_Up");
criLipsDeformer.LipsMorph = lipsMorph;
其后,通过将 CriWare.CriLipsDeformerForAtomSource 挂载至 CriWare.CriAtomSource
所添加的CriAtomSource播放的音频会被ADX LipSync解析,并反映至角色模型的变形目标。
注意需要将CriAtomSource中预定播放的音频采样率注册至 CriWare.CriLipsDeformerForAtomSource::atomAnalyzer
criLipsDeformer.AttachToAtomSource(atomSource)
// Set the sampling rate of the cue to be played.
CriAtomEx.WaveformInfo waveformInfo;
CriAtom.GetAcb(atomSource.cueSheet).GetWaveFormInfo(atomSource.cueName, out waveformInfo);
criLipsDeformer.atomAnalyzer.SetSamplingRate(waveformInfo.samplingRate);