optimize performance
This commit is contained in:
@@ -32,6 +32,7 @@ public class UmaLyricsData
|
||||
public string text;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class EmotionKey
|
||||
{
|
||||
public FacialMorph morph;
|
||||
@@ -46,11 +47,7 @@ public class FaceTypeData
|
||||
|
||||
public FaceEmotionKeyTarget target;
|
||||
|
||||
public List<EmotionKey> mouthTarget;
|
||||
public List<EmotionKey> eyeLTarget;
|
||||
public List<EmotionKey> eyeRTarget;
|
||||
public List<EmotionKey> eyebrowLTarget;
|
||||
public List<EmotionKey> eyebrowRTarget;
|
||||
public List<EmotionKey> emotionKeys;
|
||||
|
||||
private float _weight;
|
||||
public float Weight
|
||||
|
||||
@@ -187,7 +187,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
container.Slider.value = morph.Weight;
|
||||
container.Slider.maxValue = 1;
|
||||
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();
|
||||
MouthMorphs[3].Weight = 1;
|
||||
ChangeMorphWeight(MouthMorphs[3], 1);
|
||||
|
||||
if (UmaViewerUI.Instance)
|
||||
{
|
||||
UmaViewerUI.Instance.LoadFacialPanels(this);
|
||||
@@ -153,6 +154,7 @@ namespace Gallop
|
||||
{
|
||||
morph._weight = 0;
|
||||
}
|
||||
ChangeMorph();
|
||||
}
|
||||
|
||||
private void ProcessMorph(FacialMorph morph)
|
||||
@@ -198,6 +200,21 @@ namespace Gallop
|
||||
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;
|
||||
emotion.target = this;
|
||||
|
||||
InitializeEmotionTarget(ref emotion.mouthTarget,ref emotion.mouthTarget, FaceDrivenKeyTarget.MouthMorphs, emotion.mouth, false);
|
||||
InitializeEmotionTarget(ref emotion.eyeLTarget, ref emotion.eyeLTarget, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_l, true);
|
||||
InitializeEmotionTarget(ref emotion.eyeRTarget, ref emotion.eyeRTarget, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_r, false);
|
||||
InitializeEmotionTarget(ref emotion.eyebrowLTarget, ref emotion.eyebrowLTarget, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_l, true);
|
||||
InitializeEmotionTarget(ref emotion.eyebrowRTarget, ref emotion.eyebrowRTarget, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_r, false);
|
||||
emotion.emotionKeys = new List<EmotionKey>();
|
||||
InitializeEmotionTarget(emotion,FaceDrivenKeyTarget.MouthMorphs, emotion.mouth, false);
|
||||
InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_l, true);
|
||||
InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeMorphs, emotion.eye_r, false);
|
||||
InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_l, true);
|
||||
InitializeEmotionTarget(emotion, FaceDrivenKeyTarget.EyeBrowMorphs, emotion.eyebrow_r, false);
|
||||
}
|
||||
|
||||
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('|'))
|
||||
{
|
||||
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.weight = Convert.ToInt32(splitArray[1]);
|
||||
emotionKeys.Add(newValue);
|
||||
faceTypeData.emotionKeys.Add(newValue);
|
||||
Debug.Log(newValue.weight);
|
||||
}
|
||||
else
|
||||
@@ -62,7 +61,7 @@ public class FaceEmotionKeyTarget : ScriptableObject
|
||||
newValue.morph = morphs.Where(a => a.tag == morphName && a.direction == direction).First();
|
||||
}
|
||||
newValue.weight = 100;
|
||||
emotionKeys.Add(newValue);
|
||||
faceTypeData.emotionKeys.Add(newValue);
|
||||
Debug.Log(morphName);
|
||||
}
|
||||
}
|
||||
@@ -72,43 +71,24 @@ public class FaceEmotionKeyTarget : ScriptableObject
|
||||
{
|
||||
if (FaceDrivenKeyTarget == null) return;
|
||||
FaceDrivenKeyTarget.ClearMorph();
|
||||
Dictionary<FacialMorph, float> morphs = new Dictionary<FacialMorph, float>();
|
||||
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 (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;
|
||||
if (morphs.ContainsKey(key.morph))
|
||||
{
|
||||
morphs[key.morph] = key.morph.Weight + key.weight / 100 * emotion.Weight;
|
||||
}
|
||||
else
|
||||
{
|
||||
morphs.Add(key.morph, key.morph.Weight + key.weight / 100 * emotion.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
FaceDrivenKeyTarget.ChangeMorphWeights(morphs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace Gallop
|
||||
set
|
||||
{
|
||||
_weight = value;
|
||||
target.ChangeMorph();
|
||||
}
|
||||
}
|
||||
public List<TrsArray> trsArray;
|
||||
|
||||
Reference in New Issue
Block a user