bug fix, home animation facial support

This commit is contained in:
CroakFang
2023-03-28 17:57:53 +08:00
parent 5670b4bf8e
commit fc9bbda74f
20 changed files with 1058 additions and 196 deletions
+159 -69
View File
@@ -447,7 +447,7 @@ public class UmaViewerBuilder : MonoBehaviour
var hairasset = UmaViewerMain.Instance.AbChara.FirstOrDefault(a => a.Name == hair);
bool isDefaultHead = true;
if (asset != null && hairasset != null)
{
//Load Face And Hair Textures
@@ -521,7 +521,7 @@ public class UmaViewerBuilder : MonoBehaviour
CurrentUMAContainer.MergeModel();
CurrentUMAContainer.Initialize();
CurrentUMAContainer.SetHeight(-1);
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"homestand{personality.PadLeft(2,'0')}_loop")));
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"homestand{personality.PadLeft(2, '0')}_loop")));
}
private void LoadMiniUma(CharaEntry chara, string costumeId)
@@ -934,7 +934,7 @@ public class UmaViewerBuilder : MonoBehaviour
}
else if (bundle.name.Contains("/head/"))
{
if (bundle.name.Contains("_hair")&&!bundle.name.Contains("mchr"))
if (bundle.name.Contains("_hair") && !bundle.name.Contains("mchr"))
{
LoadHair(go);
}
@@ -981,10 +981,10 @@ public class UmaViewerBuilder : MonoBehaviour
{
CurrentUMAContainer.GenericBodyTextures.Add(tex2D);
}
else if (bundle.name.Contains("_face")|| bundle.name.Contains("_hair"))
else if (bundle.name.Contains("_face") || bundle.name.Contains("_hair"))
{
if(CurrentUMAContainer.IsMob)
CurrentUMAContainer.MobHeadTextures.Add(tex2D);
if (CurrentUMAContainer.IsMob)
CurrentUMAContainer.MobHeadTextures.Add(tex2D);
}
break;
}
@@ -1199,7 +1199,7 @@ public class UmaViewerBuilder : MonoBehaviour
m.SetTexture("_ToonMap", textures.LastOrDefault(t => t.name.Contains("_face") && t.name.EndsWith("shad_c")));
m.SetTexture("_TripleMaskMap", textures.LastOrDefault(t => t.name.Contains("_face") && t.name.EndsWith("base")));
m.SetTexture("_OptionMaskMap", textures.LastOrDefault(t => t.name.Contains("_face") && t.name.EndsWith("ctrl")));
m.SetTexture("_MaskColorTex", textures.LastOrDefault(t => t.name.Contains("_face") && t.name.EndsWith("area")&&! t.name.Contains("_eye")));
m.SetTexture("_MaskColorTex", textures.LastOrDefault(t => t.name.Contains("_face") && t.name.EndsWith("area") && !t.name.Contains("_eye")));
SetMaskColor(m, CurrentUMAContainer.MobHeadColor, "mayu", true);
}
if (m.name.EndsWith("mayu"))
@@ -1221,7 +1221,7 @@ public class UmaViewerBuilder : MonoBehaviour
{
if (isMob)
{
CurrentUMAContainer.CheekTex_0 = CurrentUMAContainer.MobHeadTextures.FindLast(a=>a.name.Contains("cheek0"));
CurrentUMAContainer.CheekTex_0 = CurrentUMAContainer.MobHeadTextures.FindLast(a => a.name.Contains("cheek0"));
CurrentUMAContainer.CheekTex_1 = CurrentUMAContainer.MobHeadTextures.FindLast(a => a.name.Contains("cheek1"));
}
else
@@ -1289,7 +1289,7 @@ public class UmaViewerBuilder : MonoBehaviour
m.shader = alphaShader;
}
if(m.name.EndsWith("_hair"))
if (m.name.EndsWith("_hair"))
{
m.SetTexture("_MainTex", textures.FirstOrDefault(t => t.name.Contains("_hair") && t.name.EndsWith("diff")));
m.SetTexture("_ToonMap", textures.FirstOrDefault(t => t.name.Contains("_hair") && t.name.EndsWith("shad_c")));
@@ -1440,51 +1440,12 @@ public class UmaViewerBuilder : MonoBehaviour
{
if (clip.name.EndsWith("_S"))
{
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_s"] = clip;
}
else if (clip.name.EndsWith("_E"))
{
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.OverrideController["clip_e"] = clip;
}
else if (clip.name.EndsWith("_loop"))
{
CurrentUMAContainer.UpBodyReset();
UmaDatabaseEntry motion_e = null, motion_s = null;
if (clip.name.EndsWith("_loop"))
{
motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
}
if (CurrentUMAContainer.OverrideController["clip_2"].name.EndsWith("_loop"))
{
motion_e = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e")));
}
if (CurrentUMAContainer.isAnimatorControl && CurrentUMAContainer.FaceDrivenKeyTarget)
{
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
bool needTransit = false;
needTransit = (motion_s != null && motion_e != null);
if (needTransit)
{
RecursiveLoadAsset(motion_e);
RecursiveLoadAsset(motion_s);
}
SetPreviewCamera(null);
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");
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.SetHeight(-1);
}
else if (clip.name.Contains("tail"))
{
if (CurrentUMAContainer.IsMini) return;
@@ -1495,17 +1456,12 @@ public class UmaViewerBuilder : MonoBehaviour
else if (clip.name.Contains("face"))
{
if (CurrentUMAContainer.IsMini) return;
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
CurrentUMAContainer.FaceOverrideController["clip_1"] = clip;
CurrentUMAContainer.isAnimatorControl = true;
CurrentUMAContainer.SetHeight(0);
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 0, 0);
LoadFaceAnimation(clip);
}
else if (clip.name.Contains("ear"))
{
if (CurrentUMAContainer.IsMini) return;
CurrentUMAContainer.FaceOverrideController["clip_2"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 1, 0);
LoadEarAnimation(clip);
}
else if (clip.name.Contains("pos"))
{
@@ -1517,12 +1473,61 @@ public class UmaViewerBuilder : MonoBehaviour
{
SetPreviewCamera(clip);
}
else
else if (clip.name.Contains("_loop"))
{
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.UmaAnimator.Rebind();
if (CurrentUMAContainer.isAnimatorControl && CurrentUMAContainer.FaceDrivenKeyTarget)
{
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
CurrentUMAContainer.isAnimatorControl = false;
}
var facialMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name + "_face"));
if (facialMotion != null)
{
RecursiveLoadAsset(facialMotion);
}
var earMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name + "_ear"));
if (earMotion != null)
{
RecursiveLoadAsset(earMotion);
}
UmaDatabaseEntry motion_e = null, motion_s = null;
motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
if (motion_s != null)
{
RecursiveLoadAsset(motion_s);
}
if (CurrentUMAContainer.OverrideController["clip_2"].name.Contains("_loop"))
{
motion_e = Main.AbMotions.FirstOrDefault(a =>
a.Name.EndsWith(CurrentUMAContainer.OverrideController["clip_2"].name.Replace("_loop", "_e"))
&& !a.Name.Contains("hom_")); //home end animation not for interpolation
if (motion_e != null)
{
RecursiveLoadAsset(motion_e);
}
}
SetPreviewCamera(null);
CurrentUMAContainer.OverrideController["clip_1"] = CurrentUMAContainer.OverrideController["clip_2"];
var lastTime = CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
CurrentUMAContainer.OverrideController["clip_2"] = clip;
CurrentUMAContainer.UmaAnimator.Play("motion_1", -1, 0);
CurrentUMAContainer.UmaAnimator.SetTrigger((motion_s != null && motion_e != null) ? "next_e" : ((motion_s != null) ? "next_s" : "next"));
}
else
{
if (CurrentUMAContainer.FaceDrivenKeyTarget)
{
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
CurrentUMAContainer.isAnimatorControl = false;
}
CurrentUMAContainer.UpBodyReset();
CurrentUMAContainer.UmaAnimator.Rebind();
CurrentUMAContainer.OverrideController["clip_2"] = clip;
// If Cut-in, play immediately without state interpolation
if (clip.name.Contains("crd") || clip.name.Contains("res_chr"))
@@ -1557,8 +1562,6 @@ public class UmaViewerBuilder : MonoBehaviour
SetPreviewCamera(null);
}
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
if (clip.name.Contains("cti_crd"))
{
string[] param = clip.name.Split('_');
@@ -1575,15 +1578,11 @@ public class UmaViewerBuilder : MonoBehaviour
clip.AddEvent(aevent);
}
}
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
}
else
{
if (CurrentUMAContainer.FaceDrivenKeyTarget)
{
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
}
CurrentUMAContainer.isAnimatorControl = false;
CurrentUMAContainer.SetHeight(-1);
SetPreviewCamera(null);
//Some animations have facial animation
@@ -1598,12 +1597,101 @@ public class UmaViewerBuilder : MonoBehaviour
RecursiveLoadAsset(earMotion);
}
CurrentUMAContainer.UmaAnimator.Play("motion_1", 0, lastTime);
CurrentUMAContainer.UmaAnimator.SetTrigger("next");
CurrentUMAContainer.UmaAnimator.Play("motion_2", 0, 0);
}
}
}
public void LoadFaceAnimation(AnimationClip clip)
{
if (clip.name.Contains("_S"))
{
CurrentUMAContainer.FaceOverrideController["clip_s"] = clip;
}
else if (clip.name.Contains("_E"))
{
CurrentUMAContainer.FaceOverrideController["clip_e"] = clip;
}
else if (clip.name.Contains("_loop"))
{
CurrentUMAContainer.isAnimatorControl = true;
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
UmaDatabaseEntry motion_e = null, motion_s = null;
motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
if (motion_s != null)
{
RecursiveLoadAsset(motion_s);
}
if (CurrentUMAContainer.FaceOverrideController["clip_2"].name.Contains("_loop"))
{
motion_e = Main.AbMotions.FirstOrDefault(a =>
a.Name.EndsWith(CurrentUMAContainer.FaceOverrideController["clip_2"].name.Replace("_loop", "_e"))
&& !a.Name.Contains("hom_"));
if (motion_e != null)
{
RecursiveLoadAsset(motion_e);
}
}
CurrentUMAContainer.FaceOverrideController["clip_1"] = CurrentUMAContainer.FaceOverrideController["clip_2"];
CurrentUMAContainer.FaceOverrideController["clip_2"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 0, 0);
CurrentUMAContainer.UmaFaceAnimator.SetTrigger((motion_s != null && motion_e != null) ? "next_e" : ((motion_s != null) ? "next_s" : "next"));
}
else
{
CurrentUMAContainer.isAnimatorControl = true;
CurrentUMAContainer.FaceDrivenKeyTarget.ResetLocator();
CurrentUMAContainer.FaceOverrideController["clip_2"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_2", 0, 0);
}
}
public void LoadEarAnimation(AnimationClip clip)
{
if (clip.name.Contains("_S"))
{
CurrentUMAContainer.FaceOverrideController["clip_s_ear"] = clip;
}
else if (clip.name.Contains("_E"))
{
CurrentUMAContainer.FaceOverrideController["clip_e_ear"] = clip;
}
else if (clip.name.Contains("_loop"))
{
UmaDatabaseEntry motion_e = null, motion_s = null;
motion_s = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name.Replace("_loop", "_s")));
if (motion_s != null)
{
RecursiveLoadAsset(motion_s);
}
if (CurrentUMAContainer.FaceOverrideController["clip_2_ear"].name.Contains("_loop"))
{
motion_e = Main.AbMotions.FirstOrDefault(a =>
a.Name.EndsWith(CurrentUMAContainer.FaceOverrideController["clip_2_ear"].name.Replace("_loop", "_e"))
&& !a.Name.Contains("hom_"));
if (motion_e != null)
{
RecursiveLoadAsset(motion_e);
}
}
CurrentUMAContainer.FaceOverrideController["clip_1_ear"] = CurrentUMAContainer.FaceOverrideController["clip_2_ear"];
CurrentUMAContainer.FaceOverrideController["clip_2_ear"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 1, 0);
CurrentUMAContainer.UmaFaceAnimator.SetTrigger((motion_s != null && motion_e != null) ? "next_e_ear" : ((motion_s != null) ? "next_s_ear" : "next_ear"));
}
else
{
CurrentUMAContainer.FaceOverrideController["clip_2_ear"] = clip;
CurrentUMAContainer.UmaFaceAnimator.Play("motion_2", 1, 0);
}
}
public void SetPreviewCamera(AnimationClip clip)
{
if (clip)
@@ -1615,10 +1703,12 @@ public class UmaViewerBuilder : MonoBehaviour
(AnimationCameraAnimator.runtimeAnimatorController as AnimatorOverrideController)["clip_1"] = clip;
AnimationCamera.enabled = true;
AnimationCameraAnimator.Play("motion_1", 0, 0);
CurrentUMAContainer.SetHeight(0);
}
else
{
AnimationCamera.enabled = false;
CurrentUMAContainer.SetHeight(-1);
}
}
@@ -1823,7 +1913,7 @@ public class UmaViewerBuilder : MonoBehaviour
mat.SetColor("_MaskToonColorB2", t6);
}
private void SetMaskColor(Material mat, DataRow colordata, string prefix,bool hastoon)
private void SetMaskColor(Material mat, DataRow colordata, string prefix, bool hastoon)
{
mat.EnableKeyword("USE_MASK_COLOR");
Color c1, c2, c3, c4, c5, c6, t1, t2, t3, t4, t5, t6;
+1 -3
View File
@@ -5,9 +5,6 @@ using UnityEngine;
using System;
using Newtonsoft.Json.Linq;
using System.Collections;
using static ManifestCategory;
using BaseNcoding;
using System.Text;
public class UmaViewerMain : MonoBehaviour
{
@@ -63,6 +60,7 @@ public class UmaViewerMain : MonoBehaviour
}
});
}
//Mob names (EN & JP)
yield return UmaViewerDownload.DownloadText("https://www.tracenacademy.com/api/BasicMobDataInfo", txt =>
{
+2 -3
View File
@@ -140,8 +140,6 @@ public class UmaViewerUI : MonoBehaviour
AnimationPlayButton.onClick.AddListener(AnimationPause);
AnimationSlider.onValueChanged.AddListener(AnimationProgressChange);
AnimationSpeedSlider.onValueChanged.AddListener(AnimationSpeedChange);
if (Application.platform == RuntimePlatform.Android)
canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Shrink;
}
private void Start()
{
@@ -168,7 +166,7 @@ public class UmaViewerUI : MonoBehaviour
{
if (Builder.CurrentUMAContainer.OverrideController["clip_2"].name != "clip_2")
{
bool isLoop = Builder.CurrentUMAContainer.OverrideController["clip_2"].name.EndsWith("_loop");
bool isLoop = Builder.CurrentUMAContainer.OverrideController["clip_2"].name.Contains("_loop");
var AnimeState = Builder.CurrentUMAContainer.UmaAnimator.GetCurrentAnimatorStateInfo(0);
var AnimeClip = Builder.CurrentUMAContainer.OverrideController["clip_2"];
if (AnimeClip && Builder.CurrentUMAContainer.UmaAnimator.speed != 0)
@@ -1000,6 +998,7 @@ public class UmaViewerUI : MonoBehaviour
Builder.CurrentUMAContainer.EnableEyeTracking = isOn;
}
}
public void SetFaceOverrideEnable(bool isOn)
{
EnableFaceOverride = isOn;
+2 -2
View File
@@ -5,8 +5,8 @@
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:800597811bcc5d848b15e12807d6de45",
"GUID:d60799ab2a985554ea1a39cd38695018",
"GUID:145e2572884581c48a08acf566c1a1d6",
"GUID:fd1d627189c561043911a07470238b9c"
"GUID:fd1d627189c561043911a07470238b9c",
"GUID:145e2572884581c48a08acf566c1a1d6"
],
"includePlatforms": [],
"excludePlatforms": [],