From e9c0a7a4284af3dee978c878c76955078b50cf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E7=9C=8B?= <1918891542@qq.com> Date: Thu, 6 Jul 2023 17:34:17 +0800 Subject: [PATCH] improve live --- Assets/Scripts/UmaViewerAudio.cs | 2 + .../umamusume/Gallop/FaceDrivenKeyTarget.cs | 368 ++++++++++++++---- .../Gallop/Live/Cutt/FacialDataUpdateInfo.cs | 6 +- .../Gallop/Live/Cutt/LiveTimelineControl.cs | 28 ++ .../LiveTimelineFacialData.cs | 2 +- .../Scripts/umamusume/Gallop/Live/Director.cs | 3 +- 6 files changed, 339 insertions(+), 70 deletions(-) diff --git a/Assets/Scripts/UmaViewerAudio.cs b/Assets/Scripts/UmaViewerAudio.cs index 6e9e355..171b8cf 100644 --- a/Assets/Scripts/UmaViewerAudio.cs +++ b/Assets/Scripts/UmaViewerAudio.cs @@ -49,6 +49,8 @@ public class UmaViewerAudio static public void AlterUpdate(float _liveCurrentTime, PartEntry partInfo, List liveVocal) { var timeLineData = partInfo.PartSettings["time"]; + + //need to improve var targetIndex = 0; for (int i = timeLineData.Count - 1; i >= 0; i--) { diff --git a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs index 7379e8d..7c7a0fe 100644 --- a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs +++ b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using UnityEngine; using static DynamicBone; using static Gallop.DrivenKeyComponent; +using static Gallop.FaceDrivenKeyTarget; namespace Gallop { @@ -38,6 +39,12 @@ namespace Gallop List leftEyeMorph = new List(); List rightEyeMorph = new List(); + + List leftEyebrowMorph = new List(); + List rightEyebrowMorph = new List(); + + List leftEarMorph = new List(); + List rightEarMorph = new List(); public void Initialize(List objs) { Objs = objs; @@ -78,6 +85,9 @@ namespace Gallop } else { + if (morph.direction) leftEarMorph.Add(morph); + else rightEarMorph.Add(morph); + EarMorphs.Add(morph); } } @@ -104,6 +114,9 @@ namespace Gallop } else { + if (morph.direction) leftEyebrowMorph.Add(morph); + else rightEyebrowMorph.Add(morph); + EyeBrowMorphs.Add(morph); } } @@ -140,11 +153,10 @@ namespace Gallop if (morph.direction) LeftEyeYrange = morph; else RightEyeYrange = morph; } - else - { - if (morph.direction) leftEyeMorph.Add(morph); - else rightEyeMorph.Add(morph); - } + + if (morph.direction) leftEyeMorph.Add(morph); + else rightEyeMorph.Add(morph); + EyeMorphs.Add(morph); } } @@ -376,6 +388,20 @@ namespace Gallop ApplyRotationMouth(); } + public void ChangeMorphEyebrow() + { + FacialResetEyebrow(); + EyeBrowMorphs.ForEach(morph => ProcessMorph(morph)); + ApplyRotationEyebrow(); + } + + public void ChangeMorphEar() + { + FacialResetEar(); + EarMorphs.ForEach(morph => ProcessMorph(morph)); + ApplyRotationEar(); + } + public void ClearMorph() { EarMorphs.ForEach(morph => morph.weight = 0); @@ -494,7 +520,7 @@ namespace Gallop } FacialReset(BaseLEyeMorph.trsArray); FacialReset(BaseREyeMorph.trsArray); - ApplyRotationEye(); + //ApplyRotationEye(); } public void FacialResetMouth() @@ -504,7 +530,29 @@ namespace Gallop OverrideFace(Container.FaceOverrideData); } FacialReset(BaseMouthMorph.trsArray); - ApplyRotationMouth(); + //ApplyRotationMouth(); + } + + public void FacialResetEyebrow() + { + if (Container.FaceOverrideData && Container.FaceOverrideData.Enable) + { + OverrideFace(Container.FaceOverrideData); + } + FacialReset(BaseLEyeBrowMorph.trsArray); + FacialReset(BaseREyeBrowMorph.trsArray); + //ApplyRotationEyebrow(); + } + + public void FacialResetEar() + { + if (Container.FaceOverrideData && Container.FaceOverrideData.Enable) + { + OverrideFace(Container.FaceOverrideData); + } + FacialReset(BaseLEarMorph.trsArray); + FacialReset(BaseREarMorph.trsArray); + //ApplyRotationEyebrow(); } public void FacialReset(List trsArrays) @@ -567,6 +615,48 @@ namespace Gallop applyRotation.Invoke(BaseMouthMorph.trsArray); } + public void ApplyRotationEyebrow() + { + Action> applyRotation = delegate (List trsArray) + { + foreach (TrsArray trs in trsArray) + { + if (trs.transform) + trs.transform.localRotation = RotationConvert.fromMaya(RotationRecorder[trs.transform]); + } + }; + applyRotation.Invoke(BaseLEyeBrowMorph.trsArray); + applyRotation.Invoke(BaseREyeBrowMorph.trsArray); + } + + public void ApplyRotationEar() + { + Action> applyRotation = delegate (List trsArray) + { + foreach (TrsArray trs in trsArray) + { + if(trs.isPhysics && Container.EnablePhysics) + { + trs.physicsParticle.m_InitLocalRotation = RotationConvert.fromMaya(ParticleRecorder[trs.physicsParticle]); + } + else if (trs.transform) + { + if (RotationRecorder.ContainsKey(trs.transform)) + { + //Debug.Log("Key Found:" + trs.transform.name); + trs.transform.localRotation = RotationConvert.fromMaya(RotationRecorder[trs.transform]); + } + else + { + //Debug.Log("No Key Found:" + trs.transform.name); + } + } + } + }; + applyRotation.Invoke(BaseLEarMorph.trsArray); + applyRotation.Invoke(BaseREarMorph.trsArray); + } + public void ChangeMorphWeight(FacialMorph morph, float val) { Container.isAnimatorControl = false; @@ -723,16 +813,24 @@ namespace Gallop private LiveTimelineKeyLipSyncData _prevLipKeyData; private LiveTimelineKeyLipSyncData _lastLipKeyData; - public void AlterUpdateAutoLip(LiveTimelineKeyLipSyncData keyData_, float liveTime_) + public void AlterUpdateAutoLip(LiveTimelineKeyLipSyncData keyData_, float liveTime_, float _switch) { - //Debug.Log((float)keyData_.frame); - //Debug.Log(liveTime_); + + if(_switch == 0) + { + _prevLipKeyData = null; + _lastLipKeyData = null; + MouthMorphs.ForEach(morph => morph.weight = 0); + ChangeMorphMouth(); + return; + } if(_lastLipKeyData != keyData_) { _prevLipKeyData = _lastLipKeyData; } + /* float keyTime = (float)keyData_.frame / 60; float easeTime = (float)keyData_.time/ 60; @@ -767,7 +865,8 @@ namespace Gallop break; } } - + */ + float weightRatio = CalcMorphWeight(liveTime_, keyData_.time, keyData_.interpolateType, keyData_, null); MouthMorphs.ForEach(morph => morph.weight = 0); @@ -805,6 +904,12 @@ namespace Gallop private LiveTimelineKeyFacialEyeData _prevEyesKeyData; private LiveTimelineKeyFacialEyeData _lastEyesKeyData; + private LiveTimelineKeyFacialEyebrowData _prevEyebrowsKeyData; + private LiveTimelineKeyFacialEyebrowData _lastEyebrowsKeyData; + + private LiveTimelineKeyFacialEarData _prevEarsKeyData; + private LiveTimelineKeyFacialEarData _lastEarsKeyData; + public void AlterUpdateFacialNew(ref FacialDataUpdateInfo updateInfo_, float liveTime_) { if(updateInfo_.eyeCur != null) @@ -814,61 +919,7 @@ namespace Gallop _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; - } - } + float weightRatio = CalcMorphWeight(liveTime_, updateInfo_.eyeCur.time, updateInfo_.eyeCur.interpolateType, updateInfo_.eyeCur, updateInfo_.eyeNext); EyeMorphs.ForEach(morph => morph.weight = 0); @@ -917,6 +968,191 @@ namespace Gallop _lastEyesKeyData = updateInfo_.eyeCur; } + + if (updateInfo_.eyebrowCur != null) + { + if (_lastEyebrowsKeyData != updateInfo_.eyebrowCur) + { + _prevEyebrowsKeyData = _lastEyebrowsKeyData; + } + + float weightRatio = CalcMorphWeight(liveTime_, updateInfo_.eyebrowCur.time, updateInfo_.eyebrowCur.interpolateType, updateInfo_.eyebrowCur, updateInfo_.eyebrowNext); + + EyeBrowMorphs.ForEach(morph => morph.weight = 0); + + if (_prevEyebrowsKeyData != null) + { + if (weightRatio != 1) + { + foreach (var part in _prevEyebrowsKeyData.facialPartsDataArrayL) + { + if (part.FacialPartsId == 0) { continue; } + leftEyebrowMorph[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevEyebrowsKeyData.weight / 100); + } + foreach (var part in _prevEyebrowsKeyData.facialPartsDataArrayR) + { + if (part.FacialPartsId == 0) { continue; } + rightEyebrowMorph[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevEyebrowsKeyData.weight / 100); + } + } + else + { + foreach (var part in _prevEyebrowsKeyData.facialPartsDataArrayL) + { + if (part.FacialPartsId == 0) { continue; } + leftEyebrowMorph[part.FacialPartsId - 1].weight = 0; + } + foreach (var part in _prevEyebrowsKeyData.facialPartsDataArrayR) + { + if (part.FacialPartsId == 0) { continue; } + rightEyebrowMorph[part.FacialPartsId - 1].weight = 0; + } + } + } + + foreach (var part in updateInfo_.eyebrowCur.facialPartsDataArrayL) + { + if (part.FacialPartsId == 0) { continue; } + leftEyebrowMorph[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)updateInfo_.eyebrowCur.weight / 100); + } + foreach (var part in updateInfo_.eyebrowCur.facialPartsDataArrayR) + { + if (part.FacialPartsId == 0) { continue; } + rightEyebrowMorph[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)updateInfo_.eyebrowCur.weight / 100); + } + + ChangeMorphEyebrow(); + + _lastEyebrowsKeyData = updateInfo_.eyebrowCur; + } + + if (updateInfo_.earCur != null) + { + if (_lastEarsKeyData != updateInfo_.earCur) + { + _prevEarsKeyData = _lastEarsKeyData; + } + + float weightRatio = CalcMorphWeight(liveTime_, updateInfo_.earCur.time, updateInfo_.earCur.interpolateType, updateInfo_.earCur, updateInfo_.earNext); + + EarMorphs.ForEach(morph => morph.weight = 0); + + if (_prevEarsKeyData != null) + { + if (weightRatio != 1) + { + var partL = _prevEarsKeyData.facialEarIdL; + + if (partL != 0) + { + leftEarMorph[partL - 1].weight = (((1 - weightRatio)) * ((float)_prevEarsKeyData.weight / 100)); + } + + var partR = _prevEarsKeyData.facialEarIdR; + + if (partR != 0) + { + leftEarMorph[partR - 1].weight = (((1 - weightRatio)) * ((float)_prevEarsKeyData.weight / 100)); + } + } + else + { + var partL = _prevEarsKeyData.facialEarIdL; + + if (partL != 0) + { + leftEarMorph[partL - 1].weight = 0; + } + + var partR = _prevEarsKeyData.facialEarIdR; + + if (partR != 0) + { + leftEarMorph[partR - 1].weight = 0; + } + } + } + + var curPartL = updateInfo_.earCur.facialEarIdL; + + if (curPartL != 0) + { + leftEarMorph[curPartL - 1].weight += weightRatio * ((float)updateInfo_.earCur.weight / 100); + } + + var curPartR = updateInfo_.earCur.facialEarIdR; + + if (curPartR != 0) + { + leftEarMorph[curPartR - 1].weight += weightRatio * ((float)updateInfo_.earCur.weight / 100); + } + + ChangeMorphEar(); + + _lastEarsKeyData = updateInfo_.earCur; + } + } + + public float CalcMorphWeight(float time, int interFrame, InterpolateType interType, LiveTimelineKey curKey, LiveTimelineKey nextKey) + { + + float keyTime = (float)curKey.frame / 60; + + + float duringTime; + if (nextKey != null) + { + duringTime = nextKey.frame - curKey.frame; + } + else + { + duringTime = interFrame; + } + + float easeTime; + + if (duringTime < interFrame) + { + easeTime = (float)duringTime / 60; + } + else + { + easeTime = (float)interFrame / 60; + } + + + float passTime = time - keyTime; + + float weightRatio = 0; + + if (passTime >= easeTime) + { + weightRatio = 1; + } + else + { + float ratio = passTime / easeTime; + switch (interType) + { + 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; + } + } + + return weightRatio; } } } diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs index bdd280b..fc3a5c1 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs @@ -12,9 +12,11 @@ namespace Gallop.Live.Cutt public LiveTimelineKeyFacialMouthData mouth; // 0x10 public LiveTimelineKeyFacialEyeData eyeCur; // 0x18 public LiveTimelineKeyFacialEyeData eyeNext; // 0x20 - public LiveTimelineKeyFacialEyebrowData eyebrow; // 0x28 + public LiveTimelineKeyFacialEyebrowData eyebrowCur; // 0x28 + public LiveTimelineKeyFacialEyebrowData eyebrowNext; // 0x28 public LiveTimelineKeyFacialEyeTrackData eyeTrack; // 0x30 - public LiveTimelineKeyFacialEarData ear; // 0x38 + public LiveTimelineKeyFacialEarData earCur; // 0x38 + public LiveTimelineKeyFacialEarData earNext; // 0x38 public LiveTimelineKeyFacialEffectData effect; // 0x40 public int faceKeyIndex; // 0x48 public int mouthKeyIndex; // 0x4C diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs index 94f41c8..864af03 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs @@ -113,6 +113,8 @@ namespace Gallop.Live.Cutt if (facialDataList != null) { SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime); + SetupFacialUpdateInfo_Eyebrow(ref updateInfo, facialDataList.eyebrowKeys, liveTime); + SetupFacialUpdateInfo_Ear(ref updateInfo, facialDataList.earKeys, liveTime); this.OnUpdateFacial(updateInfo, liveTime); } } @@ -130,6 +132,32 @@ namespace Gallop.Live.Cutt updateInfo.eyeKeyIndex = curKey.index; } + private void SetupFacialUpdateInfo_Eyebrow(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyebrowDataList keys, float time) + { + LiveTimelineKey liveTimelineKey = null; + LiveTimelineKey liveTimelineKey2 = null; + + LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time); + liveTimelineKey = curKey.key; + liveTimelineKey2 = curKey.nextKey; + updateInfo.eyebrowCur = liveTimelineKey as LiveTimelineKeyFacialEyebrowData; + updateInfo.eyebrowNext = liveTimelineKey2 as LiveTimelineKeyFacialEyebrowData; + updateInfo.eyebrowKeyIndex = curKey.index; + } + + private void SetupFacialUpdateInfo_Ear(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEarDataList keys, float time) + { + LiveTimelineKey liveTimelineKey = null; + LiveTimelineKey liveTimelineKey2 = null; + + LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time); + liveTimelineKey = curKey.key; + liveTimelineKey2 = curKey.nextKey; + updateInfo.earCur = liveTimelineKey as LiveTimelineKeyFacialEarData; + updateInfo.earNext = liveTimelineKey2 as LiveTimelineKeyFacialEarData; + updateInfo.earKeyIndex = curKey.index; + } + public void AlterUpdate_LipSync(float liveTime) { var lipDataList = data.worksheetList[0].ripSyncKeys; diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineDataList/LiveTimelineFacialData.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineDataList/LiveTimelineFacialData.cs index 70aba6f..fcd19b7 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineDataList/LiveTimelineFacialData.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineDataList/LiveTimelineFacialData.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace Gallop.Live.Cutt { - [System.Serializable] + [System.Serializable] public class LiveTimelineKeyFacialFaceData : LiveTimelineKey { public int facialId; diff --git a/Assets/Scripts/umamusume/Gallop/Live/Director.cs b/Assets/Scripts/umamusume/Gallop/Live/Director.cs index 2a11af0..cab9a98 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Director.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Director.cs @@ -12,6 +12,7 @@ using static UnityEditor.Experimental.AssetDatabaseExperimental.AssetDatabaseCou using System.Data; using System.Runtime.Remoting.Metadata.W3cXsd2001; using CriWare; +using static UmaViewerAudio; namespace Gallop.Live { @@ -386,7 +387,7 @@ namespace Gallop.Live var container = charaObjs[k].GetComponentInChildren(); if(container != null) { - container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_); + container.FaceDrivenKeyTarget.AlterUpdateAutoLip(keyData_, liveTime_, ((int)keyData_.character >> k) % 2); } } };