diff --git a/Assets/Scripts/UmaContainer.cs b/Assets/Scripts/UmaContainer.cs index da96ff3..c6af723 100644 --- a/Assets/Scripts/UmaContainer.cs +++ b/Assets/Scripts/UmaContainer.cs @@ -310,14 +310,10 @@ public class UmaContainer : MonoBehaviour PuppetMaster.mode = PuppetMaster.Mode.Active; } } - var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up * EyeHeight; - var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion); - var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, HeadBone.transform.up).eulerAngles; - if (deltaRotation.x > 180) deltaRotation.x -= 360; - if (deltaRotation.y > 180) deltaRotation.y -= 360; - var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35, -1, 1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view - FaceDrivenKeyTarget.SetEyeRange(finalRotation.x, finalRotation.y, finalRotation.x, -finalRotation.y); + var finalRotation = FaceDrivenKeyTarget.GetEyeTrackRotation(TrackTarget.transform.position); + FaceDrivenKeyTarget.SetEyeTrack(finalRotation); + var cam = Camera.main; var distance = Mathf.Clamp(cam.transform.InverseTransformPoint(HeadBone.transform.position).magnitude - 0.1f, 0, 2); var mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance); diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index fc8cef5..b46dd9a 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -100,6 +100,7 @@ public class UmaViewerBuilder : MonoBehaviour CurrentUMAContainer.IsLive = true; CurrentUMAContainer.CharaData = UmaDatabaseController.ReadCharaData(characters[i].CharaEntry); CurrentUMAContainer.transform.parent = Gallop.Live.Director.instance.charaObjs[i]; + CurrentUMAContainer.transform.localPosition = new Vector3(); LoadMobUma(characters[i].CharaEntry, characters[i].CostumeId); } else @@ -107,6 +108,7 @@ public class UmaViewerBuilder : MonoBehaviour CurrentUMAContainer.IsLive = true; CurrentUMAContainer.CharaData = UmaDatabaseController.ReadCharaData(characters[i].CharaEntry); CurrentUMAContainer.transform.parent = Gallop.Live.Director.instance.charaObjs[i]; + CurrentUMAContainer.transform.localPosition = new Vector3(); LoadNormalUma(characters[i].CharaEntry, characters[i].CostumeId); } diff --git a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs index 0d58890..4cc05d5 100644 --- a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs +++ b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs @@ -5,6 +5,8 @@ using UnityEngine; using static DynamicBone; using static Gallop.DrivenKeyComponent; using static Gallop.FaceDrivenKeyTarget; +using static Gallop.Live.Cutt.LiveTimelineDefine; +using static RootMotion.FinalIK.FBBIKHeadEffector; namespace Gallop { @@ -1050,9 +1052,79 @@ namespace Gallop ChangeMorphEar(); } + + if (updateInfo_.eyeTrackCur != null) + { + float weightRatio = CalcMorphWeight(liveTime_, updateInfo_.eyeTrackCur.speed, updateInfo_.eyeTrackCur.time, updateInfo_.eyeTrackCur.interpolateType, updateInfo_.eyeTrackCur, updateInfo_.eyeTrackNext); + + Vector2 finalRotation = new Vector2(); + + if (updateInfo_.eyeTrackPrev != null) + { + finalRotation = Vector2.Lerp(GetTimelineEyeTrackRotation(updateInfo_.eyeTrackPrev), GetTimelineEyeTrackRotation(updateInfo_.eyeTrackCur), weightRatio); + } + else + { + finalRotation = GetTimelineEyeTrackRotation(updateInfo_.eyeTrackCur); + } + + SetEyeTrack(finalRotation); + } + + } - public float CalcMorphWeight(float time, int speed, int interFrame, InterpolateType interType, LiveTimelineKey curKey, LiveTimelineKey nextKey) + public Vector2 GetTimelineEyeTrackRotation(LiveTimelineKeyFacialEyeTrackData key) + { + Vector3 target = new Vector3(); + if(CalcTargetPosition(key, ref target)) + { + return GetEyeTrackRotation(target) + new Vector2((float)key.horizontalRatePer / 100, (float)key.verticalRatePer / 100); + } + else + { + return new Vector2(0, 0) + new Vector2((float)key.horizontalRatePer / 100, (float)key.verticalRatePer / 100); + } + } + + public bool CalcTargetPosition(LiveTimelineKeyFacialEyeTrackData key, ref Vector3 target) + { + + switch (key.targetType) + { + case FacialEyeTrackTargetType.Arena: + target = Container.HeadBone.transform.position + new Vector3(0, 1, 10); + return true; + case FacialEyeTrackTargetType.DirectPosition: + target = key.DirectPosition; + return true; + default: + break; + } + + return false; + } + + public Vector2 GetEyeTrackRotation(Vector3 target) + { + var targetPosotion = target - Container.HeadBone.transform.up * Container.EyeHeight; + var deltaPos = Container.HeadBone.transform.InverseTransformPoint(targetPosotion); + var deltaRotation = Quaternion.LookRotation(deltaPos.normalized, Container.HeadBone.transform.up).eulerAngles; + if (deltaRotation.x > 180) deltaRotation.x -= 360; + if (deltaRotation.y > 180) deltaRotation.y -= 360; + + var finalRotation = new Vector2(Mathf.Clamp(deltaRotation.y / 35, -1, 1), Mathf.Clamp(-deltaRotation.x / 25, -1, 1));//Limited to the angle of view + + return finalRotation; + + } + + public void SetEyeTrack(Vector2 rotation) + { + SetEyeRange(rotation.x, rotation.y, rotation.x, -rotation.y); + } + + public static float CalcMorphWeight(float time, int speed, int interFrame, InterpolateType interType, LiveTimelineKey curKey, LiveTimelineKey nextKey) { float keyTime = (float)curKey.frame / 60; diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs index 8943372..7131083 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/FacialDataUpdateInfo.cs @@ -19,7 +19,9 @@ namespace Gallop.Live.Cutt public LiveTimelineKeyFacialEyebrowData eyebrowPrev; // 0x28 public LiveTimelineKeyFacialEyebrowData eyebrowCur; // 0x28 public LiveTimelineKeyFacialEyebrowData eyebrowNext; // 0x28 - public LiveTimelineKeyFacialEyeTrackData eyeTrack; // 0x30 + public LiveTimelineKeyFacialEyeTrackData eyeTrackPrev; // 0x30 + public LiveTimelineKeyFacialEyeTrackData eyeTrackCur; // 0x30 + public LiveTimelineKeyFacialEyeTrackData eyeTrackNext; // 0x30 public LiveTimelineKeyFacialEarData earPrev; // 0x38 public LiveTimelineKeyFacialEarData earCur; // 0x38 public LiveTimelineKeyFacialEarData earNext; // 0x38 diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineCharaLocator.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineCharaLocator.cs index efcff04..4195689 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineCharaLocator.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineCharaLocator.cs @@ -46,7 +46,7 @@ namespace Gallop.Live.Cutt public Quaternion liveCharaPositionLocalRotation { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public Vector3 liveCharaHeadPosition => UmaContainer.HeadBone.transform.position + new Vector3(0, UmaContainer.EyeHeight, 0); + public Vector3 liveCharaHeadPosition => UmaContainer.HeadBone.transform.position + new Vector3(0, 0.1f, 0); public Vector3 liveCharaWaistPosition => Bones["Waist"].position; diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs index 2d9e4f4..8175913 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs @@ -6,6 +6,7 @@ using static RootMotion.FinalIK.IKSolverVR; using System.Linq; using System.IO; using static UnityEngine.Rendering.VirtualTexturing.Debugging; +using static Gallop.Live.Cutt.LiveTimelineDefine; namespace Gallop.Live.Cutt { @@ -363,6 +364,7 @@ namespace Gallop.Live.Cutt SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime); SetupFacialUpdateInfo_Eyebrow(ref updateInfo, facialDataList.eyebrowKeys, liveTime); SetupFacialUpdateInfo_Ear(ref updateInfo, facialDataList.earKeys, liveTime); + SetupFacialUpdateInfo_EyeTrack(ref updateInfo, facialDataList.eyeTrackKeys, liveTime); this.OnUpdateFacial(updateInfo, liveTime, 0); } @@ -373,6 +375,7 @@ namespace Gallop.Live.Cutt SetupFacialUpdateInfo_Eye(ref updateInfo, otherFacialDataList[i].eyeKeys, liveTime); SetupFacialUpdateInfo_Eyebrow(ref updateInfo, otherFacialDataList[i].eyebrowKeys, liveTime); SetupFacialUpdateInfo_Ear(ref updateInfo, otherFacialDataList[i].earKeys, liveTime); + SetupFacialUpdateInfo_EyeTrack(ref updateInfo, otherFacialDataList[i].eyeTrackKeys, liveTime); this.OnUpdateFacial(updateInfo, liveTime, i+1); } } @@ -457,6 +460,26 @@ namespace Gallop.Live.Cutt } } + private void SetupFacialUpdateInfo_EyeTrack(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyeTrackDataList keys, float time) + { + LiveTimelineKey liveTimelineKey = null; + LiveTimelineKey liveTimelineKey2 = null; + LiveTimelineKey liveTimelineKey3 = null; + + LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time); + if (curKey != null) + { + liveTimelineKey = curKey.prevKey; + liveTimelineKey2 = curKey.key; + liveTimelineKey3 = curKey.nextKey; + + updateInfo.eyeTrackPrev = liveTimelineKey as LiveTimelineKeyFacialEyeTrackData; + updateInfo.eyeTrackCur = liveTimelineKey2 as LiveTimelineKeyFacialEyeTrackData; + updateInfo.eyeTrackNext = liveTimelineKey3 as LiveTimelineKeyFacialEyeTrackData; + updateInfo.eyeTrackKeyIndex = curKey.index; + } + } + public void AlterUpdate_LipSync(float liveTime) { var lipDataList = data.worksheetList[0].ripSyncKeys; @@ -578,14 +601,14 @@ namespace Gallop.Live.Cutt if(nextKey != null && nextKey.interpolateType != LiveCameraInterpolateType.None) { float ratio = CalculateInterpolationValue(curKey, nextKey, time * 60); - chara.transform.position = Vector3.Lerp(curKey.Position, nextKey.Position, ratio); + chara.transform.localPosition = Vector3.Lerp(curKey.Position, nextKey.Position, ratio); var x = chara.Position.localEulerAngles.x; var z = chara.Position.localEulerAngles.z; chara.Position.localEulerAngles = new Vector3(x, Mathf.Lerp(curKey.LocalRotationY, nextKey.LocalRotationY, ratio), z); } else { - chara.transform.position = curKey.Position; + chara.transform.localPosition = curKey.Position; var x = chara.Position.localEulerAngles.x; var z = chara.Position.localEulerAngles.z; chara.Position.localEulerAngles = new Vector3(x, curKey.LocalRotationY, z); diff --git a/Assets/Scripts/umamusume/Gallop/Live/Director.cs b/Assets/Scripts/umamusume/Gallop/Live/Director.cs index 8e03feb..010bb4d 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Director.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Director.cs @@ -686,7 +686,7 @@ namespace Gallop.Live { _liveCurrentTime += Time.deltaTime; - //Debug.Log(_liveCurrentTime * 60); + Debug.Log(_liveCurrentTime * 60); UI.ProgressBar.SetValueWithoutNotify(_liveCurrentTime / totalTime); OnTimelineUpdate(_liveCurrentTime);