diff --git a/Assets/Scripts/UmaContainer.cs b/Assets/Scripts/UmaContainer.cs index 6caa125..1ae9f71 100644 --- a/Assets/Scripts/UmaContainer.cs +++ b/Assets/Scripts/UmaContainer.cs @@ -7,6 +7,8 @@ using UnityEngine; public class UmaContainer : MonoBehaviour { + UmaViewerUI UI => UmaViewerUI.Instance; + public JObject CharaData; public GameObject Body; public GameObject Tail; @@ -20,7 +22,7 @@ public class UmaContainer : MonoBehaviour [Header("Face")] public List FacialClips = new List(); public FaceDrivenKeyTarget FaceDrivenKeyTargets; - + public List FaceEmotionKey; [Header("Generic")] public bool IsGeneric = false; @@ -132,4 +134,60 @@ public class UmaContainer : MonoBehaviour spring.InitializePhysics(); } } + + private void Update() + { + if(FaceDrivenKeyTargets != null) + { + if (FaceDrivenKeyTargets.needUpdate) + { + FaceDrivenKeyTargets.ChangeMorph(); + FaceDrivenKeyTargets.needUpdate = false; + } + if (FaceDrivenKeyTargets.needAllUpdate) + { + FaceDrivenKeyTargets.ClearMorph(); + foreach(var emotion in FaceEmotionKey) + { + if(emotion.mouthTarget != null) + { + foreach (var key in emotion.mouthTarget) + { + key.morph.Weight += key.weight / 100 * emotion.Weight; + } + } + if (emotion.eyeLTarget != null) + { + foreach (var key in emotion.eyeLTarget) + { + key.morph.Weight += key.weight / 100 * emotion.Weight; + } + } + if (emotion.eyeRTarget != null) + { + foreach (var key in emotion.eyeRTarget) + { + key.morph.Weight += key.weight / 100 * emotion.Weight; + } + } + if (emotion.eyebrowLTarget != null) + { + foreach (var key in emotion.eyeRTarget) + { + key.morph.Weight += key.weight / 100 * emotion.Weight; + } + } + if (emotion.eyebrowRTarget != null) + { + foreach (var key in emotion.eyeRTarget) + { + key.morph.Weight += key.weight / 100 * emotion.Weight; + } + } + } + FaceDrivenKeyTargets.ChangeMorph(); + FaceDrivenKeyTargets.needAllUpdate = false; + } + } + } } diff --git a/Assets/Scripts/UmaDatabase/UmaDataTypes.cs b/Assets/Scripts/UmaDatabase/UmaDataTypes.cs index ca4c401..3585d87 100644 --- a/Assets/Scripts/UmaDatabase/UmaDataTypes.cs +++ b/Assets/Scripts/UmaDatabase/UmaDataTypes.cs @@ -1,6 +1,8 @@ -using System.Collections; +using RootMotion.Dynamics; +using System.Collections; using System.Collections.Generic; using UnityEngine; +using Gallop; public class UmaDatabaseEntry { @@ -30,11 +32,39 @@ public class UmaLyricsData public string text; } +public class EmotionKey +{ + public FacialMorph morph; + public float weight; +} + [System.Serializable] public class FaceTypeData { public string label, eyebrow_l, eyebrow_r, eye_l, eye_r, mouth, inverce_face_type; public int mouth_shape_type, set_face_group; + + public FaceDrivenKeyTarget target; + + public List mouthTarget; + public List eyeLTarget; + public List eyeRTarget; + public List eyebrowLTarget; + public List eyebrowRTarget; + + private float _weight; + public float Weight + { + get + { + return _weight; + } + set + { + _weight = value; + target.needAllUpdate = true; + } + } } public enum UmaFileType diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index 8071388..ad03aa5 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -272,6 +272,8 @@ public class UmaViewerBuilder : MonoBehaviour var firsehead = CurrentUMAContainer.Head; var FaceDriven = firsehead.GetComponent()._assetTable.list.Find(a => { return a.Key == "facial_target"; }).Value as FaceDrivenKeyTarget; CurrentUMAContainer.FaceDrivenKeyTargets = FaceDriven; + CurrentUMAContainer.FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList(); + CurrentUMAContainer.FaceDrivenKeyTargets.Container = CurrentUMAContainer; FaceDriven.Initialize(firsehead.GetComponentsInChildren().ToList()); } diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index 846edf6..68692b7 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -31,6 +32,7 @@ public class UmaViewerUI : MonoBehaviour public ScrollRect PropList; public ScrollRect SceneList; + public ScrollRect EmotionList; public ScrollRect FacialList; public ScrollRect LiveList; public ScrollRect LiveSoundList; @@ -77,6 +79,8 @@ public class UmaViewerUI : MonoBehaviour public bool isCriware = false; public bool isHeadFix = false; + public FaceDrivenKeyTarget currentMorph; + private void Awake() { Instance = this; @@ -184,6 +188,214 @@ public class UmaViewerUI : MonoBehaviour } } + public void UpdateFacialPanels() + { + LoadFacialPanels(currentMorph); + } + + public void LoadEmotionPanels(FaceDrivenKeyTarget target) + { + foreach (UmaUIContainer ui in EmotionList.content.GetComponentsInChildren()) + { + Destroy(ui.gameObject); + } + + + + foreach(var emotion in target.Container.FaceEmotionKey) + { + if(emotion.label == "Base") + { + continue; + } + + emotion.target = target; + + emotion.mouthTarget = new List(); + foreach(var morphName in emotion.mouth.Split('|')) + { + EmotionKey newValue = new EmotionKey(); + if (morphName.Contains("__")) + { + var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase); + if(splitArray[0] == "Base") + { + continue; + } + else + { + newValue.morph = target.MouthMorphs.Where(a => a.tag == splitArray[0]).First(); + } + newValue.weight = Convert.ToInt32(splitArray[1]); + UnityEngine.Debug.Log(newValue.weight); + emotion.mouthTarget.Add(newValue); + } + else + { + UnityEngine.Debug.Log(morphName); + if (morphName == "Base") + { + continue; + } + else + { + newValue.morph = target.MouthMorphs.Where(a => a.tag == morphName).First(); + } + newValue.weight = 100; + emotion.mouthTarget.Add(newValue); + } + } + + emotion.eyeLTarget = new List(); + foreach (var morphName in emotion.eye_l.Split('|')) + { + EmotionKey newValue = new EmotionKey(); + if (morphName.Contains("__")) + { + var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase); + if (splitArray[0] == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeMorphs.Where(a => a.tag == splitArray[0] && a.direction == true).First(); + } + newValue.weight = Convert.ToInt32(splitArray[1]); + UnityEngine.Debug.Log(newValue.weight); + emotion.mouthTarget.Add(newValue); + } + else + { + UnityEngine.Debug.Log(morphName); + if (morphName == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeMorphs.Where(a => a.tag == morphName && a.direction == true).First(); + } + newValue.weight = 100; + emotion.mouthTarget.Add(newValue); + } + } + + emotion.eyeRTarget = new List(); + foreach (var morphName in emotion.eye_r.Split('|')) + { + EmotionKey newValue = new EmotionKey(); + if (morphName.Contains("__")) + { + var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase); + if (splitArray[0] == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeMorphs.Where(a => a.tag == splitArray[0] && a.direction == false).First(); + } + newValue.weight = Convert.ToInt32(splitArray[1]); + UnityEngine.Debug.Log(newValue.weight); + emotion.mouthTarget.Add(newValue); + } + else + { + UnityEngine.Debug.Log(morphName); + if (morphName == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeMorphs.Where(a => a.tag == morphName && a.direction == false).First(); + } + newValue.weight = 100; + emotion.mouthTarget.Add(newValue); + } + } + + emotion.eyebrowLTarget = new List(); + foreach (var morphName in emotion.eyebrow_l.Split('|')) + { + EmotionKey newValue = new EmotionKey(); + if (morphName.Contains("__")) + { + var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase); + if (splitArray[0] == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeBrowMorphs.Where(a => a.tag == splitArray[0] && a.direction == true).First(); + } + newValue.weight = Convert.ToInt32(splitArray[1]); + UnityEngine.Debug.Log(newValue.weight); + emotion.mouthTarget.Add(newValue); + } + else + { + UnityEngine.Debug.Log(morphName); + if (morphName == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeBrowMorphs.Where(a => a.tag == morphName && a.direction == true).First(); + } + newValue.weight = 100; + emotion.mouthTarget.Add(newValue); + } + } + + emotion.eyebrowRTarget = new List(); + foreach (var morphName in emotion.eyebrow_r.Split('|')) + { + EmotionKey newValue = new EmotionKey(); + if (morphName.Contains("__")) + { + var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase); + if (splitArray[0] == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeBrowMorphs.Where(a => a.tag == splitArray[0] && a.direction == false).First(); + } + newValue.weight = Convert.ToInt32(splitArray[1]); + UnityEngine.Debug.Log(newValue.weight); + emotion.mouthTarget.Add(newValue); + } + else + { + UnityEngine.Debug.Log(morphName); + if (morphName == "Base") + { + continue; + } + else + { + newValue.morph = target.EyeBrowMorphs.Where(a => a.tag == morphName && a.direction == false).First(); + } + newValue.weight = 100; + emotion.mouthTarget.Add(newValue); + } + } + + + var container = Instantiate(UmaContainerSliderPrefab, EmotionList.content).GetComponent(); + container.Name.text = emotion.label; + container.Slider.value = emotion.Weight; + container.Slider.maxValue = 1; + container.Slider.minValue = 0; + container.Slider.onValueChanged.AddListener((a) => { emotion.Weight = a; }); + } + } + public void LoadLivePanels() { foreach (var live in Main.Lives.OrderBy(c => c.MusicId)) diff --git a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs index be9c558..f757c99 100644 --- a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs +++ b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs @@ -22,6 +22,10 @@ namespace Gallop public List EyeMorphs = new List(); public List MouthMorphs = new List(); + public bool needUpdate = false; + public bool needAllUpdate = false; + public UmaContainer Container; + Dictionary RotationRecorder = new Dictionary(); public void Initialize(List objs) { @@ -106,6 +110,8 @@ namespace Gallop FacialReset(); MouthMorphs[3].Weight = 1; if (UmaViewerUI.Instance) { UmaViewerUI.Instance.LoadFacialPanels(this); } + if (UmaViewerUI.Instance) { UmaViewerUI.Instance.LoadEmotionPanels(this); } + if (UmaViewerUI.Instance) { UmaViewerUI.Instance.currentMorph = this; } } public void ChangeMorph() @@ -129,6 +135,25 @@ namespace Gallop ApplyRotation(); } + + public void ClearMorph() + { + foreach (FacialMorph morph in EyeBrowMorphs) + { + morph._weight = 0; + } + + foreach (FacialMorph morph in EyeMorphs) + { + morph._weight = 0; + } + + foreach (FacialMorph morph in MouthMorphs) + { + morph._weight = 0; + } + } + private void ProcessMorph(FacialMorph morph) { foreach (TrsArray trs in morph.trsArray) diff --git a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs index c7a0dca..f5b443b 100644 --- a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs +++ b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs @@ -14,7 +14,7 @@ namespace Gallop public string tag = ""; public bool direction; public FaceDrivenKeyTarget target; - private float _weight; + public float _weight; public float Weight { get @@ -24,7 +24,7 @@ namespace Gallop set { _weight = value; - target.ChangeMorph(); + target.needUpdate = true; } } public List trsArray; diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 99b6b22..1ebb68e 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -5,7 +5,7 @@ "depth": 1, "source": "registry", "dependencies": {}, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.assetbundlebrowser": { "version": "https://github.com/Unity-Technologies/AssetBundles-Browser.git", @@ -21,14 +21,14 @@ "dependencies": { "com.unity.services.core": "1.0.1" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.ext.nunit": { "version": "1.0.6", "depth": 1, "source": "registry", "dependencies": {}, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.formats.fbx": { "version": "4.1.2", @@ -38,7 +38,7 @@ "com.unity.timeline": "1.5.2", "com.autodesk.fbx": "4.1.1" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.ide.rider": { "version": "2.0.7", @@ -47,7 +47,7 @@ "dependencies": { "com.unity.test-framework": "1.1.1" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.ide.visualstudio": { "version": "2.0.16", @@ -56,14 +56,14 @@ "dependencies": { "com.unity.test-framework": "1.1.9" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.ide.vscode": { "version": "1.2.5", "depth": 0, "source": "registry", "dependencies": {}, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.postprocessing": { "version": "3.2.2", @@ -72,7 +72,7 @@ "dependencies": { "com.unity.modules.physics": "1.0.0" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.services.core": { "version": "1.0.1", @@ -81,7 +81,7 @@ "dependencies": { "com.unity.modules.unitywebrequest": "1.0.0" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.test-framework": { "version": "1.1.31", @@ -92,7 +92,7 @@ "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.textmeshpro": { "version": "3.0.6", @@ -101,7 +101,7 @@ "dependencies": { "com.unity.ugui": "1.0.0" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.timeline": { "version": "1.5.2", @@ -113,7 +113,7 @@ "com.unity.modules.audio": "1.0.0", "com.unity.modules.particlesystem": "1.0.0" }, - "url": "https://packages.unity.com" + "url": "https://packages.unity.cn" }, "com.unity.ugui": { "version": "1.0.0",