LiveTimelineEyeData support

This commit is contained in:
左右看
2023-07-06 02:48:51 +08:00
parent c6641f85d1
commit 998ec9d14f
21 changed files with 573 additions and 279 deletions
@@ -373,7 +373,7 @@ namespace Gallop
{
FacialResetMouth();
MouthMorphs.ForEach(morph => ProcessMorph(morph));
ApplyRotationEye();
ApplyRotationMouth();
}
public void ClearMorph()
@@ -504,7 +504,7 @@ namespace Gallop
OverrideFace(Container.FaceOverrideData);
}
FacialReset(BaseMouthMorph.trsArray);
ApplyRotation();
ApplyRotationMouth();
}
public void FacialReset(List<TrsArray> trsArrays)
@@ -554,6 +554,19 @@ namespace Gallop
applyRotation.Invoke(BaseREyeMorph.trsArray);
}
public void ApplyRotationMouth()
{
Action<List<TrsArray>> applyRotation = delegate (List<TrsArray> trsArray)
{
foreach (TrsArray trs in trsArray)
{
if (trs.transform)
trs.transform.localRotation = RotationConvert.fromMaya(RotationRecorder[trs.transform]);
}
};
applyRotation.Invoke(BaseMouthMorph.trsArray);
}
public void ChangeMorphWeight(FacialMorph morph, float val)
{
Container.isAnimatorControl = false;
@@ -707,17 +720,17 @@ namespace Gallop
return morphs.Find(m => m.index == (int)Type);
}
private LiveTimelineKeyLipSyncData _prevKeyData;
private LiveTimelineKeyLipSyncData _lastKeyData;
private LiveTimelineKeyLipSyncData _prevLipKeyData;
private LiveTimelineKeyLipSyncData _lastLipKeyData;
public void AlterUpdateAutoLip(LiveTimelineKeyLipSyncData keyData_, float liveTime_)
{
//Debug.Log((float)keyData_.frame);
//Debug.Log(liveTime_);
if(_lastKeyData != keyData_)
if(_lastLipKeyData != keyData_)
{
_prevKeyData = _lastKeyData;
_prevLipKeyData = _lastLipKeyData;
}
float keyTime = (float)keyData_.frame / 60;
@@ -758,19 +771,19 @@ namespace Gallop
MouthMorphs.ForEach(morph => morph.weight = 0);
if (_prevKeyData != null)
if (_prevLipKeyData != null)
{
if(weightRatio != 1)
{
foreach (var part in _prevKeyData.facialPartsDataArray)
foreach (var part in _prevLipKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0 ) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevKeyData.weight / 100);
MouthMorphs[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevLipKeyData.weight / 100);
}
}
else
{
foreach (var part in _prevKeyData.facialPartsDataArray)
foreach (var part in _prevLipKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = 0;
@@ -786,7 +799,124 @@ namespace Gallop
ChangeMorphMouth();
_lastKeyData = keyData_;
_lastLipKeyData = keyData_;
}
private LiveTimelineKeyFacialEyeData _prevEyesKeyData;
private LiveTimelineKeyFacialEyeData _lastEyesKeyData;
public void AlterUpdateFacialNew(ref FacialDataUpdateInfo updateInfo_, float liveTime_)
{
if(updateInfo_.eyeCur != null)
{
if (_lastEyesKeyData != updateInfo_.eyeCur)
{
_prevEyesKeyData = _lastEyesKeyData;
}
float keyTime = (float)updateInfo_.eyeCur.frame / 60;
float duringTime;
if (updateInfo_.eyeNext != null)
{
duringTime = updateInfo_.eyeNext.frame - updateInfo_.eyeCur.frame;
}
else
{
duringTime = updateInfo_.eyeCur.time;
}
float easeTime;
if (duringTime < updateInfo_.eyeCur.time)
{
easeTime = (float)duringTime / 60;
}
else
{
easeTime = (float)updateInfo_.eyeCur.time / 60;
}
float passTime = liveTime_ - keyTime;
float weightRatio = 0;
if (passTime >= easeTime)
{
weightRatio = 1;
}
else
{
float ratio = passTime / easeTime;
switch (updateInfo_.eyeCur.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;
}
}
EyeMorphs.ForEach(morph => morph.weight = 0);
if (_prevEyesKeyData != null)
{
if (weightRatio != 1)
{
foreach (var part in _prevEyesKeyData.facialPartsDataArrayL)
{
if (part.FacialPartsId == 0) { continue; }
leftEyeMorph[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevEyesKeyData.weight / 100);
}
foreach (var part in _prevEyesKeyData.facialPartsDataArrayR)
{
if (part.FacialPartsId == 0) { continue; }
rightEyeMorph[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevEyesKeyData.weight / 100);
}
}
else
{
foreach (var part in _prevEyesKeyData.facialPartsDataArrayL)
{
if (part.FacialPartsId == 0) { continue; }
leftEyeMorph[part.FacialPartsId - 1].weight = 0;
}
foreach (var part in _prevEyesKeyData.facialPartsDataArrayR)
{
if (part.FacialPartsId == 0) { continue; }
rightEyeMorph[part.FacialPartsId - 1].weight = 0;
}
}
}
foreach (var part in updateInfo_.eyeCur.facialPartsDataArrayL)
{
if (part.FacialPartsId == 0) { continue; }
leftEyeMorph[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)updateInfo_.eyeCur.weight / 100);
}
foreach (var part in updateInfo_.eyeCur.facialPartsDataArrayR)
{
if (part.FacialPartsId == 0) { continue; }
rightEyeMorph[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)updateInfo_.eyeCur.weight / 100);
}
ChangeMorphEye();
_lastEyesKeyData = updateInfo_.eyeCur;
}
}
}
}
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gallop.Live.Cutt
{
public struct FacialDataUpdateInfo // TypeDefIndex: 29410
{
// Fields
public LiveTimelineKeyFacialFaceData faceCur; // 0x0
public LiveTimelineKeyFacialFaceData faceNext; // 0x8
public LiveTimelineKeyFacialMouthData mouth; // 0x10
public LiveTimelineKeyFacialEyeData eyeCur; // 0x18
public LiveTimelineKeyFacialEyeData eyeNext; // 0x20
public LiveTimelineKeyFacialEyebrowData eyebrow; // 0x28
public LiveTimelineKeyFacialEyeTrackData eyeTrack; // 0x30
public LiveTimelineKeyFacialEarData ear; // 0x38
public LiveTimelineKeyFacialEffectData effect; // 0x40
public int faceKeyIndex; // 0x48
public int mouthKeyIndex; // 0x4C
public int eyeKeyIndex; // 0x50
public int eyebrowKeyIndex; // 0x54
public int eyeTrackKeyIndex; // 0x58
public int earKeyIndex; // 0x5C
public int effectKeyIndex; // 0x60
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d23729e48867d7143b85da3439885191
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -14,8 +14,10 @@ namespace Gallop.Live.Cutt
//public abstract string Description { get; set; }
//public abstract int depthCounter { get; }
LiveTimelineKey FindCurrentKey(float currentTime);
public abstract LiveTimelineKeyIndex TimeKeyIndex { get; }
LiveTimelineKeyIndex FindCurrentKey(float currentTime);
LiveTimelineKeyIndex UpdateCurrentKey(float currentTime);
}
}
@@ -27,6 +27,8 @@ namespace Gallop.Live.Cutt
public event Action<LiveTimelineKeyLipSyncData, float> OnUpdateLipSync;
public event Action<FacialDataUpdateInfo, float> OnUpdateFacial;
public void CopyValues<T>(T from, T to)
{
var json = JsonUtility.ToJson(from);
@@ -93,6 +95,7 @@ namespace Gallop.Live.Cutt
{
AlterUpdate_CharaMotionSequence(liveTime);
AlterUpdate_LipSync(liveTime);
AlterUpdate_FacialData(liveTime);
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
@@ -103,23 +106,68 @@ namespace Gallop.Live.Cutt
}
}
public void AlterUpdate_FacialData(float liveTime)
{
var facialDataList = data.worksheetList[0].facial1Set;
FacialDataUpdateInfo updateInfo = default(FacialDataUpdateInfo);
if (facialDataList != null)
{
SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime);
this.OnUpdateFacial(updateInfo, liveTime);
}
}
private void SetupFacialUpdateInfo_Eye(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyeDataList keys, float time)
{
LiveTimelineKey liveTimelineKey = null;
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyeCur = liveTimelineKey as LiveTimelineKeyFacialEyeData;
updateInfo.eyeNext = liveTimelineKey2 as LiveTimelineKeyFacialEyeData;
updateInfo.eyeKeyIndex = curKey.index;
}
public void AlterUpdate_LipSync(float liveTime)
{
var lipDataList = data.worksheetList[0].ripSyncKeys;
LiveTimelineKey curKey = null;
FindTimelineKeyCurrent(out curKey, lipDataList, liveTime);
if (curKey != null)
LiveTimelineKeyIndex curKey = AlterUpdate_Key(lipDataList, liveTime);
if (curKey != null && curKey.index != -1)
{
LiveTimelineKeyLipSyncData arg = curKey as LiveTimelineKeyLipSyncData;
LiveTimelineKeyLipSyncData arg = curKey.key as LiveTimelineKeyLipSyncData;
this.OnUpdateLipSync(arg, liveTime);
}
}
public void FindTimelineKeyCurrent(out LiveTimelineKey curKey, ILiveTimelineKeyDataList keys, float curTime)
public static void FindTimelineKeyCurrent(out LiveTimelineKeyIndex curKey, ILiveTimelineKeyDataList keys, float curTime)
{
curKey = keys.FindCurrentKey(curTime);
}
public static void UpdateTimelineKeyCurrent(out LiveTimelineKeyIndex curKey, ILiveTimelineKeyDataList keys, float curTime)
{
curKey = keys.UpdateCurrentKey(curTime);
}
public static LiveTimelineKeyIndex AlterUpdate_Key(ILiveTimelineKeyDataList keys, float curTime)
{
LiveTimelineKeyIndex curKey = keys.TimeKeyIndex;
if (curKey.index == -1)
{
FindTimelineKeyCurrent(out curKey, keys, curTime);
}
else
{
UpdateTimelineKeyCurrent(out curKey, keys, curTime);
}
return curKey;
}
}
@@ -58,61 +58,20 @@ namespace Gallop.Live.Cutt
{
if (_currentKey != null && _tempAnim != null)
{
/*
var seqs = _currentKey.thisList;
LiveTimelineKeyIndex curKey = LiveTimelineControl.AlterUpdate_Key(_currentKey, currentTime);
for (int i = seqs.Count - 1; i >= 0; i--)
if (curKey != null && curKey.index != -1)
{
Debug.Log(currentTime);
if (currentTime >= (double)seqs[i].frame / 60)
{
Debug.Log("ʱ¼ä:" + ((double)seqs[i].frame / 60).ToString());
LiveTimelineKeyCharaMotionData arg = curKey.key as LiveTimelineKeyCharaMotionData;
AnimationClip anim = seqs[i].clip;
double start = (double)seqs[i].motionHeadFrame / 60;
double interval = currentTime - (double)seqs[i].frame / 60;
Debug.Log("time:" + interval.ToString());
//anim.SampleAnimation(container.gameObject, (float)(start + interval));
_tempAnim[anim.name].time = (float)(start + interval);
_tempAnim.Play(anim.name);
break;
}
}
*/
var timelineKey = GetKey(currentTime);
//if ( _prevKey != timelineKey ) Play animation all the time not affect performance maybe?
if ( true )
{
AnimationClip anim = timelineKey.clip;
double start = (double)timelineKey.motionHeadFrame / 60;
double interval = currentTime - (double)timelineKey.frame / 60;
AnimationClip anim = arg.clip;
double start = (double)arg.motionHeadFrame / 60;
double interval = currentTime - (double)arg.frame / 60;
_tempAnim[anim.name].time = (float)(start + interval);
_tempAnim.Play(anim.name);
_prevKey = timelineKey;
}
}
}
public LiveTimelineKeyCharaMotionData GetKey(float time)
{
var seqs = _currentKey.thisList;
for (int i = seqs.Count - 1; i >= 0; i--)
{
if (time >= (double)seqs[i].frame / 60)
{
return seqs[i];
}
}
return seqs[0];
}
}
}
@@ -126,7 +126,12 @@ namespace Gallop.Live.Cutt
private TimelineKeyPlayMode _playMode;
public List<T> thisList;
public LiveTimelineKeyIndex thisTimeKeyIndex = new LiveTimelineKeyIndex();
public int Count => thisList.Count;
public LiveTimelineKeyIndex TimeKeyIndex => thisTimeKeyIndex;
public LiveTimelineKey this[int index]
{
@@ -140,20 +145,61 @@ namespace Gallop.Live.Cutt
}
}
public LiveTimelineKey FindCurrentKey(float currentTime)
public LiveTimelineKeyIndex FindCurrentKey(float currentTime)
{
for (int i = thisList.Count - 1; i >= 0; i--)
{
if (currentTime >= (double)thisList[i].frame / 60)
{
return thisList[i];
thisTimeKeyIndex.index = i;
thisTimeKeyIndex.key = thisList[i];
if(i+1 != thisList.Count)
{
thisTimeKeyIndex.nextKey = thisList[i + 1];
}
else
{
thisTimeKeyIndex.nextKey = null;
}
return thisTimeKeyIndex;
}
}
return null;
}
public LiveTimelineKeyIndex UpdateCurrentKey(float currentTime)
{
if (thisTimeKeyIndex.nextKey != null)
{
if (currentTime >= (double)thisTimeKeyIndex.nextKey.frame / 60)
{
thisTimeKeyIndex.index++;
thisTimeKeyIndex.key = thisList[thisTimeKeyIndex.index];
if (thisTimeKeyIndex.index + 1 != thisList.Count)
{
thisTimeKeyIndex.nextKey = thisList[thisTimeKeyIndex.index + 1];
}
else
{
thisTimeKeyIndex.nextKey = null;
}
}
}
return thisTimeKeyIndex;
}
}
[System.Serializable]
[System.Serializable]
public class LiveTimelineKeyIndex
{
public int index = -1;
public LiveTimelineKey key = null;
public LiveTimelineKey nextKey = null;
}
[System.Serializable]
public abstract class LiveTimelineKey
{
public int frame;
+114 -53
View File
@@ -11,6 +11,7 @@ using UnityEditor.SceneManagement;
using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCounters;
using System.Data;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using CriWare;
namespace Gallop.Live
{
@@ -312,9 +313,10 @@ namespace Gallop.Live
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";
private const string SONG_PATH = "sound/l/{0}/snd_bgm_live_{0}_oke_01.awb";
private const string VOCAL_PATH = "sound/l/{0}/snd_bgm_live_{0}_chara_{1}_01.awb";
private const string SONG_PATH = "sound/l/{0}/snd_bgm_live_{0}_oke_01";
private const string VOCAL_PATH = "sound/l/{0}/snd_bgm_live_{0}_chara_{1}_01";
private const string RANDOM_VOCAL_PATH = "sound/l/{0}/snd_bgm_live_{0}_chara";
private const string LIVE_PART_PATH = "live/musicscores/m{0}/m{0}_part";
private UmaViewerBuilder Builder => UmaViewerBuilder.Instance;
@@ -328,6 +330,14 @@ namespace Gallop.Live
public AudioSource liveSong;
public List<CriAtomSource> liveVocal;
public CriAtomSource liveMusic;
public PartEntry partInfo;
public bool _syncTime = false;
public bool _soloMode = true;
private void Awake()
{
if (live != null)
@@ -336,7 +346,7 @@ namespace Gallop.Live
Debug.Log(string.Format(CUTT_PATH, live.MusicId));
Debug.Log(live.BackGroundId);
Builder.LoadAssetPath(string.Format(CUTT_PATH, live.MusicId), this.gameObject.transform);
Builder.LoadAssetPath(string.Format(STAGE_PATH, live.BackGroundId), this.gameObject.transform);
//Builder.LoadAssetPath(string.Format(STAGE_PATH, live.BackGroundId), this.gameObject.transform);
//Make CharacterObject
@@ -352,13 +362,16 @@ namespace Gallop.Live
charaObjs.Add(newObj.transform);
counter++;
};
//Set Animation
//Get live parts info
UmaDatabaseEntry partAsset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.Contains(string.Format(LIVE_PART_PATH, live.MusicId)));
Debug.Log(partAsset.Name);
AssetBundle bundle = UmaViewerBuilder.LoadOrGet(partAsset);
TextAsset partData = bundle.LoadAsset<TextAsset>($"m{live.MusicId}_part");
partInfo = new PartEntry(partData.text);
}
}
@@ -368,18 +381,6 @@ namespace Gallop.Live
_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>();
@@ -388,43 +389,81 @@ namespace Gallop.Live
container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_);
}
}
/*
};
_liveTimelineControl.OnUpdateFacial += delegate (FacialDataUpdateInfo updateInfo_, float liveTime_)
{
var container = charaObjs[0].GetComponentInChildren<UmaContainer>();
if (container != null)
{
container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_);
}
*/
container.FaceDrivenKeyTarget.AlterUpdateFacialNew(ref updateInfo_, liveTime_);
};
}
public void Play(int songid, int charaid)
public void Play(int songid, List<LiveCharacterSelect> characters)
{
Debug.Log(songid);
Debug.Log(charaid);
Debug.Log(string.Format(VOCAL_PATH, songid, charaid));
var entry = UmaViewerMain.Instance.AbSounds.FirstOrDefault(a => a.Name.Contains(string.Format(VOCAL_PATH, songid, charaid)));
if (entry == null)
if (!_soloMode)
{
List<UmaDatabaseEntry> entries = new List<UmaDatabaseEntry>();
foreach (var random in UmaViewerMain.Instance.AbSounds.Where(a => (a.Name.Contains(string.Format(RANDOM_VOCAL_PATH, songid)) && a.Name.EndsWith("awb"))))
for (int i = 0; i < characters.Count; i++)
{
entries.Add(random);
}
if (entries.Count > 0)
{
entry = entries[UnityEngine.Random.Range(0, entries.Count - 1)];
}
}
if(entry != null)
{
Debug.Log(entry.Name);
}
if (characters[i].CharaEntry.Name != "" && i < 3)
{
var charaid = characters[i].CharaEntry.Id;
UmaViewerBuilder.Instance.LoadLiveSound(songid, entry, false);
liveSong = GameObject.Find("SoundController").GetComponent<AudioSource>();
var entry = UmaViewerMain.Instance.AbSounds.FirstOrDefault(a => a.Name.Contains(string.Format(VOCAL_PATH, songid, charaid)) && a.Name.EndsWith("awb"));
if (entry == null)
{
List<UmaDatabaseEntry> entries = new List<UmaDatabaseEntry>();
foreach (var random in UmaViewerMain.Instance.AbSounds.Where(a => (a.Name.Contains(string.Format(RANDOM_VOCAL_PATH, songid)) && a.Name.EndsWith("awb"))))
{
entries.Add(random);
}
if (entries.Count > 0)
{
entry = entries[UnityEngine.Random.Range(0, entries.Count - 1)];
}
}
if (entry != null)
{
Debug.Log(entry.Name);
liveVocal.Add(UmaViewerAudio.ApplyCueSheet(entry.Name.Split('.')[0]));
}
}
}
liveMusic = UmaViewerAudio.ApplyCueSheet(string.Format(SONG_PATH, songid));
foreach (var vocal in liveVocal)
{
vocal.Play(0);
}
liveMusic.Play(0);
}
else
{
var entry = UmaViewerMain.Instance.AbSounds.FirstOrDefault(a => a.Name.Contains(string.Format(VOCAL_PATH, songid, characters[0].CharaEntry.Id)) && a.Name.EndsWith("awb"));
if (entry == null)
{
List<UmaDatabaseEntry> entries = new List<UmaDatabaseEntry>();
foreach (var random in UmaViewerMain.Instance.AbSounds.Where(a => (a.Name.Contains(string.Format(RANDOM_VOCAL_PATH, songid)) && a.Name.EndsWith("awb"))))
{
entries.Add(random);
}
if (entries.Count > 0)
{
entry = entries[UnityEngine.Random.Range(0, entries.Count - 1)];
}
}
if (entry != null)
{
Debug.Log(entry.Name);
}
UmaViewerBuilder.Instance.LoadLiveSound(songid, entry, false);
liveSong = GameObject.Find("SoundController").GetComponent<AudioSource>();
}
_isLiveSetup = true;
_liveCurrentTime = 0;
@@ -433,18 +472,40 @@ namespace Gallop.Live
private void OnTimelineUpdate(float _liveCurrentTime)
{
_liveTimelineControl.AlterUpdate(_liveCurrentTime);
if (!_soloMode)
{
UmaViewerAudio.AlterUpdate(_liveCurrentTime, partInfo, liveVocal);
}
}
void Update()
{
if (_isLiveSetup)
{
_liveCurrentTime += Time.deltaTime;
OnTimelineUpdate(_liveCurrentTime);
}
else
{
_liveCurrentTime = 0;
if(_syncTime == false)
{
if (!_soloMode)
{
if(liveMusic.time > 0)
{
_liveCurrentTime = liveMusic.time / 1000;
_syncTime = true;
}
}
else
{
if(liveSong.time > 0)
{
_liveCurrentTime = liveSong.time;
_syncTime = true;
}
}
}
else
{
_liveCurrentTime += Time.deltaTime;
OnTimelineUpdate(_liveCurrentTime);
}
}
}
}