ripSyncKeys support

This commit is contained in:
左右看
2023-07-03 18:51:54 +08:00
parent 85f12dda0e
commit 1a49208ad2
13 changed files with 397 additions and 60 deletions
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Easing
{
static public float EaseIn(float x)
{
return x * x * x;
}
static public float EaseOut(float x)
{
return 1 - Mathf.Pow(1 - x, 3);
}
static public float EaseInOut(float x)
{
return x < 0.5 ? 4 * x * x * x : 1 - Mathf.Pow(-2 * x + 2, 3) / 2;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f15c35ffe5bbd1648b777e0dea855b5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+7 -2
View File
@@ -774,7 +774,10 @@ public class UmaViewerBuilder : MonoBehaviour
public void LoadLiveSound(int songid, UmaDatabaseEntry SongAwb, bool needLyrics = true)
{
//load character voice
PlaySound(SongAwb);
if (SongAwb != null)
{
PlaySound(SongAwb);
}
//load BG
string nameVar = $"snd_bgm_live_{songid}_oke";
@@ -1536,7 +1539,9 @@ public class UmaViewerBuilder : MonoBehaviour
}
var firsehead = CurrentUMAContainer.Head;
var faceDriven = firsehead.GetComponent<AssetHolder>()._assetTable["facial_target"] as FaceDrivenKeyTarget;
var origin_faceDriven = firsehead.GetComponent<AssetHolder>()._assetTable["facial_target"] as FaceDrivenKeyTarget;
var faceDriven = new FaceDrivenKeyTarget();
DeepCopy.CopyValues(origin_faceDriven, faceDriven);
var earDriven = firsehead.GetComponent<AssetHolder>()._assetTable["ear_target"] as DrivenKeyTarget;
var faceOverride = firsehead.GetComponent<AssetHolder>()._assetTable["face_override"] as FaceOverrideData;
faceDriven._earTarget = earDriven._targetFaces;
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using UnityEngine;
using static DynamicBone;
using static Gallop.DrivenKeyComponent;
namespace Gallop
{
@@ -368,6 +369,13 @@ namespace Gallop
ApplyRotationEye();
}
public void ChangeMorphMouth()
{
FacialResetMouth();
MouthMorphs.ForEach(morph => ProcessMorph(morph));
ApplyRotationEye();
}
public void ClearMorph()
{
EarMorphs.ForEach(morph => morph.weight = 0);
@@ -386,6 +394,10 @@ namespace Gallop
private void ProcessMorph(FacialMorph morph)
{
if (morph.weight == 0)
{
return;
}
foreach (TrsArray trs in morph.trsArray)
{
if (trs.isPhysics && Container.EnablePhysics)
@@ -485,6 +497,16 @@ namespace Gallop
ApplyRotationEye();
}
public void FacialResetMouth()
{
if (Container.FaceOverrideData && Container.FaceOverrideData.Enable)
{
OverrideFace(Container.FaceOverrideData);
}
FacialReset(BaseMouthMorph.trsArray);
ApplyRotation();
}
public void FacialReset(List<TrsArray> trsArrays)
{
foreach (TrsArray trs in trsArrays)
@@ -684,5 +706,87 @@ namespace Gallop
{
return morphs.Find(m => m.index == (int)Type);
}
private LiveTimelineKeyLipSyncData _prevKeyData;
private LiveTimelineKeyLipSyncData _lastKeyData;
public void AlterUpdateAutoLip(LiveTimelineKeyLipSyncData keyData_, float liveTime_)
{
//Debug.Log((float)keyData_.frame);
//Debug.Log(liveTime_);
if(_lastKeyData != keyData_)
{
_prevKeyData = _lastKeyData;
}
float keyTime = (float)keyData_.frame / 60;
float easeTime = (float)keyData_.time/ 60;
float passTime = liveTime_ - keyTime;
float weightRatio = 0;
if (passTime >= easeTime)
{
weightRatio = 1;
}
else
{
float ratio = passTime / easeTime;
switch (keyData_.interpolateType)
{
case InterpolateType.Linear:
weightRatio = ratio;
break;
case InterpolateType.EaseIn:
weightRatio = Easing.EaseIn(ratio);
break;
case InterpolateType.EaseOut:
weightRatio = Easing.EaseOut(ratio);
break;
case InterpolateType.EaseInOut:
weightRatio = Easing.EaseInOut(ratio);
break;
default:
weightRatio = ratio;
break;
}
}
MouthMorphs.ForEach(morph => morph.weight = 0);
if (_prevKeyData != null)
{
if(weightRatio != 1)
{
foreach (var part in _prevKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0 ) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevKeyData.weight / 100);
}
}
else
{
foreach (var part in _prevKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = 0;
}
}
}
foreach (var part in keyData_.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)keyData_.weight / 100);
}
ChangeMorphMouth();
_lastKeyData = keyData_;
}
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gallop
{
[Serializable]
public struct FaceParts
{
public int _faceParts; // 0x0
public float _weight; // 0x4
public float _originalWeight; // 0x8
}
[Serializable]
public class FacePartsSet
{
private static FacePartsSet _baseFacePartsSet; // 0x0
public FaceParts[] _eyeR; // 0x10
public FaceParts[] _eyeL; // 0x18
public FaceParts[] _eyebrowR; // 0x20
public FaceParts[] _eyebrowL; // 0x28
public FaceParts[] _mouth; // 0x30
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f7da6175d3234a4294eba661b778213
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gallop.Live.Cutt
{
public interface ILiveTimelineKeyDataList
{
//public abstract LiveTimelineKey Item { get; set; }
public abstract int Count { get; }
//public abstract LiveTimelineKeyDataListAttr attribute { get; set; }
//public abstract TimelineKeyPlayMode playMode { get; set; }
//public abstract Color BaseColor { get; set; }
//public abstract string Description { get; set; }
//public abstract int depthCounter { get; }
LiveTimelineKey FindCurrentKey(float currentTime);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5dd68e207061a374f863959f57baf40c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static RootMotion.FinalIK.IKSolverVR;
namespace Gallop.Live.Cutt
{
@@ -23,6 +25,8 @@ namespace Gallop.Live.Cutt
public LiveTimelineKeyCharaMotionSeqDataList[] _keyArray;
public event Action<LiveTimelineKeyLipSyncData, float> OnUpdateLipSync;
public void CopyValues<T>(T from, T to)
{
var json = JsonUtility.ToJson(from);
@@ -88,6 +92,7 @@ namespace Gallop.Live.Cutt
public void AlterUpdate(float liveTime)
{
AlterUpdate_CharaMotionSequence(liveTime);
AlterUpdate_LipSync(liveTime);
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
@@ -97,6 +102,24 @@ namespace Gallop.Live.Cutt
motion.AlterUpdate(liveTime);
}
}
public void AlterUpdate_LipSync(float liveTime)
{
var lipDataList = data.worksheetList[0].ripSyncKeys;
LiveTimelineKey curKey = null;
FindTimelineKeyCurrent(out curKey, lipDataList, liveTime);
if (curKey != null)
{
LiveTimelineKeyLipSyncData arg = curKey as LiveTimelineKeyLipSyncData;
this.OnUpdateLipSync(arg, liveTime);
}
}
public void FindTimelineKeyCurrent(out LiveTimelineKey curKey, ILiveTimelineKeyDataList keys, float curTime)
{
curKey = keys.FindCurrentKey(curTime);
}
}
@@ -1,5 +1,6 @@
using Cutt;
using System.Collections.Generic;
using System.Windows.Forms;
using UnityEngine;
namespace Gallop.Live.Cutt
@@ -117,14 +118,40 @@ namespace Gallop.Live.Cutt
}
[System.Serializable]
public class LiveTimelineKeyDataListTemplate<T>
{
public class LiveTimelineKeyDataListTemplate<T> : ILiveTimelineKeyDataList where T : LiveTimelineKey
{
[SerializeField]
private LiveTimelineKeyDataListAttr _attribute;
[SerializeField]
private TimelineKeyPlayMode _playMode;
public List<T> thisList;
}
public int Count => thisList.Count;
public LiveTimelineKey this[int index]
{
get
{
return thisList[index];
}
set
{
thisList[index] = value as T;
}
}
public LiveTimelineKey FindCurrentKey(float currentTime)
{
for (int i = thisList.Count - 1; i >= 0; i--)
{
if (currentTime >= (double)thisList[i].frame / 60)
{
return thisList[i];
}
}
return null;
}
}
[System.Serializable]
public abstract class LiveTimelineKey
@@ -308,7 +308,7 @@ namespace Gallop.Live
public static RegisterInfo[] EffectRegisterInfoArray { get; set; }
public static Dictionary<string, List<string>> FlashSeCueNameDict { get; set; }
//
//real work start
public LiveEntry live;
private const string CUTT_PATH = "cutt/cutt_son{0}/cutt_son{0}";
private const string STAGE_PATH = "3d/env/live/live{0}/pfb_env_live{0}_controller000";
@@ -365,29 +365,42 @@ namespace Gallop.Live
public void InitializeTimeline()
{
_liveTimelineControl.InitCharaMotionSequence();
_liveTimelineControl.OnUpdateLipSync += delegate (LiveTimelineKeyLipSyncData keyData_, float liveTime_)
{
/*
for (int k = 0; k < MemberUnitNumber; k++)
{
int num4 = k % MemberUnitNumber;
if (_characterObjects[num4].isSetting)
{
_characterObjects[num4].faceController.AlterUpdateAutoLip(liveTime_, keyData_, (LiveCharaPosition)num4);
}
}
*/
for (int k = 0; k < charaObjs.Count; k++)
{
var container = charaObjs[k].GetComponentInChildren<UmaContainer>();
if(container != null)
{
container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_);
}
}
/*
var container = charaObjs[0].GetComponentInChildren<UmaContainer>();
if (container != null)
{
container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_);
}
*/
};
}
public void Play(int songid, int charaid)
{
/*
int counter = 0;
var motionSeq = this._liveTimelineControl.data.worksheetList[0].charaMotSeqList;
foreach (var seq in motionSeq)
{
var anim = seq.keys.thisList[4].clip;
var container = charaObjs[counter].GetComponentInChildren<UmaContainer>();
Debug.Log(container);
if (container != null)
{
var animation = container.gameObject.AddComponent<Animation>();
animation.AddClip(anim, anim.name);
animation.Play(anim.name);
counter++;
}
}
*/
Debug.Log(songid);
Debug.Log(charaid);
Debug.Log(string.Format(VOCAL_PATH, songid, charaid));
@@ -408,39 +421,17 @@ namespace Gallop.Live
if(entry != null)
{
Debug.Log(entry.Name);
UmaViewerBuilder.Instance.LoadLiveSound(songid, entry, false);
liveSong = GameObject.Find("SoundController").GetComponent<AudioSource>();
}
UmaViewerBuilder.Instance.LoadLiveSound(songid, entry, false);
liveSong = GameObject.Find("SoundController").GetComponent<AudioSource>();
_isLiveSetup = true;
_liveCurrentTime = 0;
}
private void OnTimelineUpdate(float _liveCurrentTime)
{
/*
var seqs = seqData[0].keys.thisList;
var container = charaObjs[0].GetComponentInChildren<UmaContainer>();
for(int i = seqs.Count - 1; i >=0; i--)
{
Debug.Log(_liveCurrentTime);
if (_liveCurrentTime >= (double)seqs[i].frame/60)
{
Debug.Log("ʱ¼ä:" + ((double)seqs[i].frame / 60).ToString());
AnimationClip anim = seqs[i].clip;
double start = (double)seqs[i].motionHeadFrame/60;
double interval = _liveCurrentTime - (double)seqs[i].frame/ 60;
Debug.Log("time:" + interval.ToString());
anim.SampleAnimation(container.gameObject, (float)(start + interval));
break;
}
}
*/
_liveTimelineControl.AlterUpdate(_liveCurrentTime);
}
@@ -448,16 +439,8 @@ namespace Gallop.Live
{
if (_isLiveSetup)
{
if(false)
{
_liveCurrentTime = liveSong.time;
OnTimelineUpdate(_liveCurrentTime);
}
else
{
_liveCurrentTime += Time.deltaTime;
OnTimelineUpdate(_liveCurrentTime);
}
_liveCurrentTime += Time.deltaTime;
OnTimelineUpdate(_liveCurrentTime);
}
else
{
@@ -0,0 +1,82 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gallop.Live
{
public class LiveFaceController : MonoBehaviour
{
private class FacePartsSetInfo
{
public FacePartsSet[] FacePartsSetArray; // 0x10
public int EyeRCount; // 0x18
public int EyeLCount; // 0x1C
public int EyebrowRCount; // 0x20
public int EyebrowLCount; // 0x24
public int MouthCount; // 0x28
}
private enum BlinkStep
{
WaitStart = 0,
SyncBlink = 1
}
private enum FacialKeyType
{
None = 0,
Face = 1,
Eye = 2
}
private const bool ENABLE_AUTO_BLINK = false;
private const float AUTO_BLINK_REPRESSION_TIME = 1;
private const int FACE_PARTS_SET_TEMP_ITEM_NUM = 1;
private float _earWeight; // 0x18
private float _earDurationTime; // 0x1C
private float _eyebrowDurationTime; // 0x20
private float _eyeDurationTime; // 0x24
private float _mouthDurationTime; // 0x28
private DrivenKeyComponent.InterpolateType _eyeInterpolateType; // 0x2C
private DrivenKeyComponent.InterpolateType _eyebrowInterpolateType; // 0x30
private DrivenKeyComponent.InterpolateType _mouthInterpolateType; // 0x34
private DrivenKeyComponent.InterpolateType _earInterpolateType; // 0x38
private DrivenKeyComponent.InterpolateType _prevEyeInterpolateType; // 0x3C
private DrivenKeyComponent.InterpolateType _prevEyebrowInterpolateType; // 0x40
private DrivenKeyComponent.InterpolateType _prevMouthInterpolateType; // 0x44
private DrivenKeyComponent.InterpolateType _prevEarInterpolateType; // 0x48
private EarType _earTypeL; // 0x4C
private EarType _earTypeR; // 0x50
private LiveFaceController.FacePartsSetInfo _facePartsSet; // 0x58
private FacePartsSet _facePartsSetTemp; // 0x60
private LiveFaceController.FacePartsSetInfo _prevFacePartsSetInfo; // 0x68
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private LiveFaceController.BlinkStep _autoBlinkStep; // 0x70
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private float _autoBlinkTimeCount; // 0x74
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private float _autoBlinkTimeInterval; // 0x78
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private int _cheekType; // 0x7C
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private int _tearyType; // 0x80
[SerializeField] // RVA: 0xEBE0 Offset: 0xEBE0 VA: 0x7FF85CCBEBE0
private int _tearfulType; // 0x84
private ModelController _modelController; // 0x88
private float _prevEarWeight; // 0x90
private float _prevEarDurationTime; // 0x94
private float _prevEyebrowDurationTime; // 0x98
private float _prevEyeDurationTime; // 0x9C
private float _prevMouthDurationTime; // 0xA0
private EarType _prevEarTypeL; // 0xA4
private EarType _prevEarTypeR; // 0xA8
private bool _isRepressAutoBlink; // 0xAC
private bool _isLipSync; // 0xAD
private const float AutoBlinkIntervalMin = 3;
private const float AutoBlinkIntervalMax = 5;
private int _blinkRno; // 0xB0
private int _currentStartFrameOfEye; // 0xB4
public bool IsUpdateAutoBlink { get; set; }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fcdfa39122e46eb4fb6d20bea4f05c6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: