optimize performance

This commit is contained in:
CroakFang
2022-11-01 22:53:52 +08:00
parent b96df921bb
commit bdeb68b029
5 changed files with 42 additions and 49 deletions
+2 -5
View File
@@ -32,6 +32,7 @@ public class UmaLyricsData
public string text; public string text;
} }
[System.Serializable]
public class EmotionKey public class EmotionKey
{ {
public FacialMorph morph; public FacialMorph morph;
@@ -46,11 +47,7 @@ public class FaceTypeData
public FaceEmotionKeyTarget target; public FaceEmotionKeyTarget target;
public List<EmotionKey> mouthTarget; public List<EmotionKey> emotionKeys;
public List<EmotionKey> eyeLTarget;
public List<EmotionKey> eyeRTarget;
public List<EmotionKey> eyebrowLTarget;
public List<EmotionKey> eyebrowRTarget;
private float _weight; private float _weight;
public float Weight public float Weight
+1 -1
View File
@@ -187,7 +187,7 @@ public class UmaViewerUI : MonoBehaviour
container.Slider.value = morph.Weight; container.Slider.value = morph.Weight;
container.Slider.maxValue = 1; container.Slider.maxValue = 1;
container.Slider.minValue = 0; container.Slider.minValue = 0;
container.Slider.onValueChanged.AddListener((a) => { morph.Weight = a;}); container.Slider.onValueChanged.AddListener((a) => { target.ChangeMorphWeight(morph, a); });
} }
} }
@@ -108,7 +108,8 @@ namespace Gallop
} }
} }
FacialResetAll(); FacialResetAll();
MouthMorphs[3].Weight = 1; ChangeMorphWeight(MouthMorphs[3], 1);
if (UmaViewerUI.Instance) if (UmaViewerUI.Instance)
{ {
UmaViewerUI.Instance.LoadFacialPanels(this); UmaViewerUI.Instance.LoadFacialPanels(this);
@@ -153,6 +154,7 @@ namespace Gallop
{ {
morph._weight = 0; morph._weight = 0;
} }
ChangeMorph();
} }
private void ProcessMorph(FacialMorph morph) private void ProcessMorph(FacialMorph morph)
@@ -198,6 +200,21 @@ namespace Gallop
trs.Key.localRotation = RotationConvert.fromMaya(trs.Value); trs.Key.localRotation = RotationConvert.fromMaya(trs.Value);
} }
} }
public void ChangeMorphWeight(FacialMorph morph,float val)
{
morph.Weight = val;
ChangeMorph();
}
public void ChangeMorphWeights(Dictionary<FacialMorph, float> morphs)
{
foreach(var item in morphs)
{
item.Key.Weight = item.Value;
}
ChangeMorph();
}
} }
} }
@@ -16,12 +16,12 @@ public class FaceEmotionKeyTarget : ScriptableObject
{ {
if (emotion.label == "Base") continue; if (emotion.label == "Base") continue;
emotion.target = this; emotion.target = this;
emotion.emotionKeys = new List<EmotionKey>();
InitializeEmotionTarget(ref emotion.mouthTarget,ref emotion.mouthTarget, FaceDrivenKeyTarget.MouthMorphs, emotion.mouth, false); InitializeEmotionTarget(emotion,FaceDrivenKeyTarget.MouthMorphs, emotion.mouth, false);
InitializeEmotionTarget(ref emotion.eyeLTarget, ref emotion.eyeLTarget, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_l, true); InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_l, true);
InitializeEmotionTarget(ref emotion.eyeRTarget, ref emotion.eyeRTarget, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_r, false); InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_r, false);
InitializeEmotionTarget(ref emotion.eyebrowLTarget, ref emotion.eyebrowLTarget, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_l, true); InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_l, true);
InitializeEmotionTarget(ref emotion.eyebrowRTarget, ref emotion.eyebrowRTarget, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_r, false); InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_r, false);
} }
if (UmaViewerUI.Instance) if (UmaViewerUI.Instance)
@@ -30,9 +30,8 @@ public class FaceEmotionKeyTarget : ScriptableObject
} }
} }
private void InitializeEmotionTarget(ref List<EmotionKey> targets, ref List<EmotionKey> emotionKeys,List<FacialMorph> morphs,string tags,bool direction) private void InitializeEmotionTarget(FaceTypeData faceTypeData, List<FacialMorph> morphs,string tags,bool direction)
{ {
targets = new List<EmotionKey>();
foreach (var morphName in tags.Split('|')) foreach (var morphName in tags.Split('|'))
{ {
EmotionKey newValue = new EmotionKey(); EmotionKey newValue = new EmotionKey();
@@ -48,7 +47,7 @@ public class FaceEmotionKeyTarget : ScriptableObject
newValue.morph = morphs.Where(a => a.tag == splitArray[0] && a.direction == direction).First(); newValue.morph = morphs.Where(a => a.tag == splitArray[0] && a.direction == direction).First();
} }
newValue.weight = Convert.ToInt32(splitArray[1]); newValue.weight = Convert.ToInt32(splitArray[1]);
emotionKeys.Add(newValue); faceTypeData.emotionKeys.Add(newValue);
Debug.Log(newValue.weight); Debug.Log(newValue.weight);
} }
else else
@@ -62,7 +61,7 @@ public class FaceEmotionKeyTarget : ScriptableObject
newValue.morph = morphs.Where(a => a.tag == morphName && a.direction == direction).First(); newValue.morph = morphs.Where(a => a.tag == morphName && a.direction == direction).First();
} }
newValue.weight = 100; newValue.weight = 100;
emotionKeys.Add(newValue); faceTypeData.emotionKeys.Add(newValue);
Debug.Log(morphName); Debug.Log(morphName);
} }
} }
@@ -72,43 +71,24 @@ public class FaceEmotionKeyTarget : ScriptableObject
{ {
if (FaceDrivenKeyTarget == null) return; if (FaceDrivenKeyTarget == null) return;
FaceDrivenKeyTarget.ClearMorph(); FaceDrivenKeyTarget.ClearMorph();
Dictionary<FacialMorph, float> morphs = new Dictionary<FacialMorph, float>();
foreach (var emotion in FaceEmotionKey) foreach (var emotion in FaceEmotionKey)
{ {
if (emotion.mouthTarget != null) if (emotion.emotionKeys != null)
{ {
foreach (var key in emotion.mouthTarget) foreach (var key in emotion.emotionKeys)
{ {
key.morph.Weight += key.weight / 100 * emotion.Weight; if (morphs.ContainsKey(key.morph))
} {
} morphs[key.morph] = key.morph.Weight + key.weight / 100 * emotion.Weight;
if (emotion.eyeLTarget != null) }
{ else
foreach (var key in emotion.eyeLTarget) {
{ morphs.Add(key.morph, key.morph.Weight + key.weight / 100 * emotion.Weight);
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;
} }
} }
FaceDrivenKeyTarget.ChangeMorphWeights(morphs);
} }
} }
} }
@@ -24,7 +24,6 @@ namespace Gallop
set set
{ {
_weight = value; _weight = value;
target.ChangeMorph();
} }
} }
public List<TrsArray> trsArray; public List<TrsArray> trsArray;