Add preset emotion

This commit is contained in:
左右看
2022-11-01 02:21:30 +08:00
parent a064cc6ffb
commit 5f5f96bf4e
7 changed files with 343 additions and 16 deletions
+59 -1
View File
@@ -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<AnimationClip> FacialClips = new List<AnimationClip>();
public FaceDrivenKeyTarget FaceDrivenKeyTargets;
public List<FaceTypeData> 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;
}
}
}
}
+31 -1
View File
@@ -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<EmotionKey> mouthTarget;
public List<EmotionKey> eyeLTarget;
public List<EmotionKey> eyeRTarget;
public List<EmotionKey> eyebrowLTarget;
public List<EmotionKey> eyebrowRTarget;
private float _weight;
public float Weight
{
get
{
return _weight;
}
set
{
_weight = value;
target.needAllUpdate = true;
}
}
}
public enum UmaFileType
+2
View File
@@ -272,6 +272,8 @@ public class UmaViewerBuilder : MonoBehaviour
var firsehead = CurrentUMAContainer.Head;
var FaceDriven = firsehead.GetComponent<AssetHolder>()._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<Transform>().ToList());
}
+212
View File
@@ -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<UmaUIContainer>())
{
Destroy(ui.gameObject);
}
foreach(var emotion in target.Container.FaceEmotionKey)
{
if(emotion.label == "Base")
{
continue;
}
emotion.target = target;
emotion.mouthTarget = new List<EmotionKey>();
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<EmotionKey>();
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<EmotionKey>();
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<EmotionKey>();
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<EmotionKey>();
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<UmaUIContainer>();
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))
@@ -22,6 +22,10 @@ namespace Gallop
public List<FacialMorph> EyeMorphs = new List<FacialMorph>();
public List<FacialMorph> MouthMorphs = new List<FacialMorph>();
public bool needUpdate = false;
public bool needAllUpdate = false;
public UmaContainer Container;
Dictionary<Transform, Vector3> RotationRecorder = new Dictionary<Transform, Vector3>();
public void Initialize(List<Transform> 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)
@@ -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> trsArray;
+12 -12
View File
@@ -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",