Merge duplicate code and optimize code
This commit is contained in:
@@ -21,8 +21,8 @@ public class UmaContainer : MonoBehaviour
|
||||
|
||||
[Header("Face")]
|
||||
public List<AnimationClip> FacialClips = new List<AnimationClip>();
|
||||
public FaceDrivenKeyTarget FaceDrivenKeyTargets;
|
||||
public List<FaceTypeData> FaceEmotionKey;
|
||||
public FaceDrivenKeyTarget FaceDrivenKeyTarget;
|
||||
public FaceEmotionKeyTarget FaceEmotionKeyTarget;
|
||||
|
||||
[Header("Generic")]
|
||||
public bool IsGeneric = false;
|
||||
@@ -33,16 +33,6 @@ public class UmaContainer : MonoBehaviour
|
||||
public bool IsMini = false;
|
||||
public List<Texture2D> MiniHeadTextures = new List<Texture2D>();
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (TryGetComponent<PuppetMaster>(out PuppetMaster t))
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
else { Destroy(gameObject); }
|
||||
|
||||
}
|
||||
|
||||
public void MergeModel()
|
||||
{
|
||||
if (!Body) return;
|
||||
@@ -94,7 +84,7 @@ public class UmaContainer : MonoBehaviour
|
||||
UmaAnimator = gameObject.AddComponent<Animator>();
|
||||
UmaAnimator.avatar = AvatarBuilder.BuildGenericAvatar(gameObject, gameObject.name);
|
||||
UmaAnimator.runtimeAnimatorController = OverrideController = Instantiate(UmaViewerBuilder.Instance.OverrideController);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Transform[] MergeBone(SkinnedMeshRenderer from, List<Transform> targetBones)
|
||||
@@ -123,71 +113,16 @@ public class UmaContainer : MonoBehaviour
|
||||
}
|
||||
}
|
||||
from.bones = tmpBone;
|
||||
return emptyBones.ToArray() ;
|
||||
return emptyBones.ToArray();
|
||||
}
|
||||
|
||||
public void LoadPhysics()
|
||||
{
|
||||
var springs = PhysicsController.GetComponentsInChildren<CySpringDataContainer>();
|
||||
var springs = PhysicsController.GetComponentsInChildren<CySpringDataContainer>();
|
||||
foreach (CySpringDataContainer spring in springs)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ 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 FaceEmotionKeyTarget target;
|
||||
|
||||
public List<EmotionKey> mouthTarget;
|
||||
public List<EmotionKey> eyeLTarget;
|
||||
@@ -62,7 +62,7 @@ public class FaceTypeData
|
||||
set
|
||||
{
|
||||
_weight = value;
|
||||
target.needAllUpdate = true;
|
||||
target.UpdateAllFacialKeyTargets();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
int head_id;
|
||||
string head_costumeId;
|
||||
int tailId = (int)charaData["tailModelId"];
|
||||
|
||||
|
||||
//The tailId of 9006 is 1, but the character has no tail
|
||||
if (id == 9006) tailId = -1;
|
||||
|
||||
@@ -192,10 +192,12 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
head_id = id;
|
||||
head_costumeId = costumeId;
|
||||
|
||||
CurrentHead = new UmaHeadData();
|
||||
CurrentHead.id = id;
|
||||
CurrentHead.costumeId = costumeId;
|
||||
CurrentHead.tailId = tailId;
|
||||
CurrentHead = new UmaHeadData
|
||||
{
|
||||
id = id,
|
||||
costumeId = costumeId,
|
||||
tailId = tailId
|
||||
};
|
||||
}
|
||||
|
||||
string head = UmaDatabaseController.HeadPath + $"chr{head_id}_{head_costumeId}/pfb_chr{head_id}_{head_costumeId}";
|
||||
@@ -237,7 +239,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (tailId != 0)
|
||||
{
|
||||
string tailName = $"tail{tailId.ToString().PadLeft(4, '0')}_00";
|
||||
@@ -271,10 +273,16 @@ 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;
|
||||
CurrentUMAContainer.FaceDrivenKeyTarget = FaceDriven;
|
||||
CurrentUMAContainer.FaceDrivenKeyTarget.Container = CurrentUMAContainer;
|
||||
FaceDriven.Initialize(firsehead.GetComponentsInChildren<Transform>().ToList());
|
||||
|
||||
CurrentUMAContainer.FaceEmotionKeyTarget = new FaceEmotionKeyTarget()
|
||||
{
|
||||
FaceDrivenKeyTarget = FaceDriven,
|
||||
FaceEmotionKey = UmaDatabaseController.Instance.FaceTypeData.ToList()
|
||||
};
|
||||
CurrentUMAContainer.FaceEmotionKeyTarget.Initialize();
|
||||
}
|
||||
|
||||
CurrentUMAContainer.MergeModel();
|
||||
@@ -389,7 +397,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
{
|
||||
var asset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.EndsWith("cutt_son" + live.MusicId));
|
||||
var BGasset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.EndsWith($"pfb_env_live{live.BackGroundId}_controller000"));
|
||||
if (asset == null|| BGasset == null) return;
|
||||
if (asset == null || BGasset == null) return;
|
||||
|
||||
UnloadLive();
|
||||
UnloadAllBundle();
|
||||
@@ -509,7 +517,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
int sampleRate = stream.WaveFormat.SampleRate;
|
||||
|
||||
AudioClip clip = AudioClip.Create(
|
||||
Path.GetFileNameWithoutExtension(awb.Name)+"_"+wave.WaveId.ToString(),
|
||||
Path.GetFileNameWithoutExtension(awb.Name) + "_" + wave.WaveId.ToString(),
|
||||
(int)(stream.Length / channels / bytesPerSample),
|
||||
channels,
|
||||
sampleRate,
|
||||
@@ -545,11 +553,11 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
bundle = AssetBundle.LoadFromFile(filePath);
|
||||
Main.LoadedBundles.Add(lyricsAsset.Name, bundle);
|
||||
}
|
||||
|
||||
|
||||
TextAsset asset = bundle.LoadAsset<TextAsset>(Path.GetFileNameWithoutExtension(lyricsVar));
|
||||
string[] lines = asset.text.Split("\n"[0]);
|
||||
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
for (int i = 1; i < lines.Length; i++)
|
||||
{
|
||||
string[] words = lines[i].Split(',');
|
||||
if (words.Length > 0)
|
||||
@@ -563,13 +571,13 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
};
|
||||
CurrentLyrics.Add(lyricsData);
|
||||
}
|
||||
catch{}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(entry.Prerequisites))
|
||||
@@ -806,7 +814,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
private void LoadHead(GameObject go)
|
||||
{
|
||||
GameObject head = Instantiate(go, CurrentUMAContainer.transform);
|
||||
CurrentUMAContainer.Head=head;
|
||||
CurrentUMAContainer.Head = head;
|
||||
|
||||
foreach (Renderer r in head.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
@@ -935,11 +943,11 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
RecursiveLoadAsset(motion_e);
|
||||
RecursiveLoadAsset(motion_s);
|
||||
}
|
||||
|
||||
|
||||
var lastTime = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
|
||||
CurrentUMAContainer.OverrideController["clip_1"] = CurrentUMAContainer.OverrideController["clip_2"];
|
||||
CurrentUMAContainer.OverrideController["clip_2"] = clip;
|
||||
|
||||
|
||||
CurrentUMAContainer.UmaAnimator.Play("motion_1", -1);
|
||||
CurrentUMAContainer.UmaAnimator.SetTrigger(needTransit ? "next_s" : "next");
|
||||
}
|
||||
@@ -1011,7 +1019,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
public void UnloadProp()
|
||||
{
|
||||
if(CurrentOtherContainer != null)
|
||||
if (CurrentOtherContainer != null)
|
||||
{
|
||||
Destroy(CurrentOtherContainer.gameObject);
|
||||
}
|
||||
@@ -1029,7 +1037,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
if (CurrentUMAContainer != null)
|
||||
{
|
||||
//It seems that OnDestroy will executed after new model loaded, which cause new FacialPanels empty...
|
||||
UmaViewerUI.Instance.currentMorph = null;
|
||||
UmaViewerUI.Instance.currentFaceDrivenKeyTarget = null;
|
||||
UmaViewerUI.Instance.LoadEmotionPanels(null);
|
||||
UmaViewerUI.Instance.LoadFacialPanels(null);
|
||||
Destroy(CurrentUMAContainer.gameObject);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
public bool isCriware = false;
|
||||
public bool isHeadFix = false;
|
||||
|
||||
public FaceDrivenKeyTarget currentMorph;
|
||||
public FaceDrivenKeyTarget currentFaceDrivenKeyTarget;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -168,10 +168,13 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public void LoadFacialPanels(FaceDrivenKeyTarget target)
|
||||
{
|
||||
currentFaceDrivenKeyTarget = target;
|
||||
|
||||
foreach (UmaUIContainer ui in FacialList.content.GetComponentsInChildren<UmaUIContainer>())
|
||||
{
|
||||
Destroy(ui.gameObject);
|
||||
}
|
||||
|
||||
if (target == null) return;
|
||||
List<FacialMorph> tempMorph = new List<FacialMorph>();
|
||||
tempMorph.AddRange(target.EyeBrowMorphs);
|
||||
@@ -190,10 +193,10 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
public void UpdateFacialPanels()
|
||||
{
|
||||
LoadFacialPanels(currentMorph);
|
||||
LoadFacialPanels(currentFaceDrivenKeyTarget);
|
||||
}
|
||||
|
||||
public void LoadEmotionPanels(FaceDrivenKeyTarget target)
|
||||
public void LoadEmotionPanels(FaceEmotionKeyTarget target)
|
||||
{
|
||||
foreach (UmaUIContainer ui in EmotionList.content.GetComponentsInChildren<UmaUIContainer>())
|
||||
{
|
||||
@@ -202,191 +205,12 @@ public class UmaViewerUI : MonoBehaviour
|
||||
|
||||
if (target == null) return;
|
||||
|
||||
foreach(var emotion in target.Container.FaceEmotionKey)
|
||||
foreach(var emotion in target.FaceEmotionKey)
|
||||
{
|
||||
if(emotion.label == "Base")
|
||||
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;
|
||||
|
||||
@@ -107,25 +107,26 @@ namespace Gallop
|
||||
}
|
||||
}
|
||||
}
|
||||
FacialReset();
|
||||
FacialResetAll();
|
||||
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; }
|
||||
if (UmaViewerUI.Instance)
|
||||
{
|
||||
UmaViewerUI.Instance.LoadFacialPanels(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ChangeMorph()
|
||||
{
|
||||
FacialReset();
|
||||
FacialResetAll();
|
||||
|
||||
foreach (FacialMorph morph in EyeBrowMorphs)
|
||||
{
|
||||
ProcessMorph(morph);
|
||||
ProcessMorph(morph);
|
||||
}
|
||||
|
||||
foreach (FacialMorph morph in EyeMorphs)
|
||||
{
|
||||
ProcessMorph(morph);
|
||||
ProcessMorph(morph);
|
||||
}
|
||||
|
||||
foreach (FacialMorph morph in MouthMorphs)
|
||||
@@ -167,76 +168,37 @@ namespace Gallop
|
||||
}
|
||||
}
|
||||
|
||||
public void FacialReset()
|
||||
public void FacialResetAll()
|
||||
{
|
||||
foreach (TrsArray trs in BaseLEyeBrowMorph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
|
||||
foreach (TrsArray trs in BaseREyeBrowMorph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
|
||||
foreach (TrsArray trs in BaseLEyeMorph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
|
||||
foreach (TrsArray trs in BaseREyeMorph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
|
||||
foreach (TrsArray trs in BaseMouthMorph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
|
||||
FacialReset(BaseLEyeBrowMorph.trsArray);
|
||||
FacialReset(BaseREyeBrowMorph.trsArray);
|
||||
FacialReset(BaseLEyeMorph.trsArray);
|
||||
FacialReset(BaseREyeMorph.trsArray);
|
||||
FacialReset(BaseMouthMorph.trsArray);
|
||||
ApplyRotation();
|
||||
}
|
||||
|
||||
public void ApplyRotation(){
|
||||
public void FacialReset(List<TrsArray> trsArrays)
|
||||
{
|
||||
foreach (TrsArray trs in trsArrays)
|
||||
{
|
||||
if (trs.transform)
|
||||
{
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyRotation()
|
||||
{
|
||||
foreach (var trs in RotationRecorder)
|
||||
{
|
||||
trs.Key.localRotation = RotationConvert.fromMaya(trs.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using Gallop;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
public class FaceEmotionKeyTarget : ScriptableObject
|
||||
{
|
||||
public List<FaceTypeData> FaceEmotionKey;
|
||||
public FaceDrivenKeyTarget FaceDrivenKeyTarget;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (var emotion in FaceEmotionKey)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (UmaViewerUI.Instance)
|
||||
{
|
||||
UmaViewerUI.Instance.LoadEmotionPanels(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeEmotionTarget(ref List<EmotionKey> targets, ref List<EmotionKey> emotionKeys,List<FacialMorph> morphs,string tags,bool direction)
|
||||
{
|
||||
targets = new List<EmotionKey>();
|
||||
foreach (var morphName in tags.Split('|'))
|
||||
{
|
||||
EmotionKey newValue = new EmotionKey();
|
||||
if (morphName.Contains("__"))
|
||||
{
|
||||
var splitArray = Regex.Split(morphName, "__", RegexOptions.IgnoreCase);
|
||||
if (splitArray[0] == "Base")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
newValue.morph = morphs.Where(a => a.tag == splitArray[0] && a.direction == direction).First();
|
||||
}
|
||||
newValue.weight = Convert.ToInt32(splitArray[1]);
|
||||
emotionKeys.Add(newValue);
|
||||
Debug.Log(newValue.weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (morphName == "Base")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
newValue.morph = morphs.Where(a => a.tag == morphName && a.direction == direction).First();
|
||||
}
|
||||
newValue.weight = 100;
|
||||
emotionKeys.Add(newValue);
|
||||
Debug.Log(morphName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAllFacialKeyTargets()
|
||||
{
|
||||
if (FaceDrivenKeyTarget == null) return;
|
||||
FaceDrivenKeyTarget.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43ba40a9c767e6e43a635ce59cb7942e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -24,7 +24,7 @@ namespace Gallop
|
||||
set
|
||||
{
|
||||
_weight = value;
|
||||
target.needUpdate = true;
|
||||
target.ChangeMorph();
|
||||
}
|
||||
}
|
||||
public List<TrsArray> trsArray;
|
||||
|
||||
+12
-12
@@ -5,7 +5,7 @@
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"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.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ext.nunit": {
|
||||
"version": "1.0.6",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"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.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "2.0.7",
|
||||
@@ -47,7 +47,7 @@
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.1"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.16",
|
||||
@@ -56,14 +56,14 @@
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.9"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.vscode": {
|
||||
"version": "1.2.5",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.postprocessing": {
|
||||
"version": "3.2.2",
|
||||
@@ -72,7 +72,7 @@
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.services.core": {
|
||||
"version": "1.0.1",
|
||||
@@ -81,7 +81,7 @@
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"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.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.textmeshpro": {
|
||||
"version": "3.0.6",
|
||||
@@ -101,7 +101,7 @@
|
||||
"dependencies": {
|
||||
"com.unity.ugui": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"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.cn"
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ugui": {
|
||||
"version": "1.0.0",
|
||||
|
||||
Reference in New Issue
Block a user