From 8b0f7384170051b24b4cdd8882e8a3bcb87b804f Mon Sep 17 00:00:00 2001 From: CroakFang <1605296300@qq.com> Date: Thu, 31 Aug 2023 00:14:14 +0800 Subject: [PATCH] fix facial stencil problem, add static tear morph --- Assets/Scripts/UmaContainerCharacter.cs | 41 ++++++++++++--- Assets/Scripts/UmaViewerBuilder.cs | 4 +- Assets/Scripts/UmaViewerUI.cs | 6 +-- .../umamusume/Gallop/FaceDrivenKeyTarget.cs | 50 +++++++++++++++---- .../Scripts/umamusume/Gallop/FacialMorph.cs | 3 +- .../umamusume/Gallop/TearController.cs | 10 +++- 6 files changed, 91 insertions(+), 23 deletions(-) diff --git a/Assets/Scripts/UmaContainerCharacter.cs b/Assets/Scripts/UmaContainerCharacter.cs index 1eec044..e938bbe 100644 --- a/Assets/Scripts/UmaContainerCharacter.cs +++ b/Assets/Scripts/UmaContainerCharacter.cs @@ -54,6 +54,8 @@ public class UmaContainerCharacter : UmaContainer public List RightMangaObject = new List(); [Header("Tear")] + public GameObject StaticTear_L; + public GameObject StaticTear_R; public GameObject TearPrefab_0; public GameObject TearPrefab_1; public List TearControllers = new List(); @@ -632,6 +634,7 @@ public class UmaContainerCharacter : UmaContainer var textures = MobHeadTextures; GameObject head = Instantiate(go, transform); Head = head; + var table = Head.GetComponent()._assetTable; //Some setting for Head EnableEyeTracking = UI.EnableEyeTracking; @@ -705,7 +708,7 @@ public class UmaContainerCharacter : UmaContainer } //Blush Setting - if (r.name.Contains("Cheek")) + if(r.name.Contains("Cheek")) { r.gameObject.SetActive(false); if (IsMob) @@ -715,11 +718,21 @@ public class UmaContainerCharacter : UmaContainer } else { - var table = Head.GetComponent()._assetTable; CheekTex_0 = table["cheek0"] as Texture; CheekTex_1 = table["cheek1"] as Texture; } } + + if(Main.AbList.TryGetValue("3d/chara/common/textures/tex_chr_tear00", out var tearEntry)) + { + var ab = UmaAssetManager.LoadAssetBundle(tearEntry, true, false); + var tex = ab.LoadAsset("tex_chr_tear00"); + StaticTear_L = table["tearmesh_l"] as GameObject; + StaticTear_R = table["tearmesh_r"] as GameObject; + StaticTear_L.GetComponent().material.mainTexture = tex; + StaticTear_R.GetComponent().material.mainTexture = tex; + } + switch (m.shader.name) { case "Gallop/3D/Chara/MultiplyCheek": @@ -747,6 +760,8 @@ public class UmaContainerCharacter : UmaContainer break; } } + + m.SetFloat("_StencilMask", CharaEntry.Id); } } @@ -1252,7 +1267,12 @@ public class UmaContainerCharacter : UmaContainer obj.SetActive(false); var leftObj = Instantiate(obj, eyeLocator_L.transform); - new List(leftObj.GetComponentsInChildren()).ForEach(a => a.material.renderQueue = -1); + new List(leftObj.GetComponentsInChildren(true)).ForEach(a => { + a.material.SetFloat("_StencilMask", id); + a.material.SetFloat("_StencilComp", (float)UnityEngine.Rendering.CompareFunction.Equal); + a.material.SetFloat("_StencilOp", (float)UnityEngine.Rendering.StencilOp.Keep); + a.material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest; + }); LeftMangaObject.Add(leftObj); var RightObj = Instantiate(obj, eyeLocator_R.transform); @@ -1261,7 +1281,12 @@ public class UmaContainerCharacter : UmaContainer if (holder._assetTableValue["invert"] > 0) RightObj.transform.localScale = new Vector3(-1, 1, 1); } - new List(RightObj.GetComponentsInChildren()).ForEach(a => { a.material.renderQueue = -1; }); + new List(RightObj.GetComponentsInChildren(true)).ForEach(a => { + a.material.SetFloat("_StencilMask", id); + a.material.SetFloat("_StencilComp", (float)UnityEngine.Rendering.CompareFunction.Equal); + a.material.SetFloat("_StencilOp", (float)UnityEngine.Rendering.StencilOp.Keep); + a.material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest; + }); RightMangaObject.Add(RightObj); }); @@ -1280,10 +1305,10 @@ public class UmaContainerCharacter : UmaContainer var p0 = TearPrefab_0; var p1 = TearPrefab_1; var t = headBone.transform; - TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 1)); - TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 1)); - TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 0, 0)); - TearControllers.Add(new TearController(t, Instantiate(p0, t), Instantiate(p1, t), 1, 0)); + TearControllers.Add(new TearController(CharaEntry.Id, t, Instantiate(p0, t), Instantiate(p1, t), 0, 1)); + TearControllers.Add(new TearController(CharaEntry.Id, t, Instantiate(p0, t), Instantiate(p1, t), 1, 1)); + TearControllers.Add(new TearController(CharaEntry.Id, t, Instantiate(p0, t), Instantiate(p1, t), 0, 0)); + TearControllers.Add(new TearController(CharaEntry.Id, t, Instantiate(p0, t), Instantiate(p1, t), 1, 0)); } var firsehead = Head; diff --git a/Assets/Scripts/UmaViewerBuilder.cs b/Assets/Scripts/UmaViewerBuilder.cs index 0283263..413dc07 100644 --- a/Assets/Scripts/UmaViewerBuilder.cs +++ b/Assets/Scripts/UmaViewerBuilder.cs @@ -49,7 +49,6 @@ public class UmaViewerBuilder : MonoBehaviour { int id = chara.Id; var umaContainer = new GameObject($"Chara_{id}_{costumeId}").AddComponent(); - umaContainer.CharaEntry = chara; CurrentUMAContainer = umaContainer; if (mini) @@ -110,6 +109,7 @@ public class UmaViewerBuilder : MonoBehaviour private void LoadNormalUma(UmaContainerCharacter umaContainer, CharaEntry chara, string costumeId, bool loadMotion = false) { int id = chara.Id; + umaContainer.CharaEntry = chara; DataRow charaData = umaContainer.CharaData; bool genericCostume = umaContainer.IsGeneric = costumeId.Length >= 4; string skin, height, socks, bust, sex, shape, costumeIdShort = ""; @@ -319,6 +319,7 @@ public class UmaViewerBuilder : MonoBehaviour private void LoadMobUma(UmaContainerCharacter umaContainer, CharaEntry chara, string costumeId, int bodyid = -1, bool loadMotion = false) { int id = chara.Id; + umaContainer.CharaEntry = chara; umaContainer.IsMob = chara.IsMob; umaContainer.MobDressColor = UmaDatabaseController.ReadMobDressColor(umaContainer.CharaData["dress_color_id"].ToString()); umaContainer.MobHeadColor = UmaDatabaseController.ReadMobHairColor(umaContainer.CharaData["chara_hair_color"].ToString()); @@ -539,6 +540,7 @@ public class UmaViewerBuilder : MonoBehaviour private void LoadMiniUma(UmaContainerCharacter umaContainer, CharaEntry chara, string costumeId) { int id = chara.Id; + umaContainer.CharaEntry = chara; DataRow charaData = umaContainer.CharaData; umaContainer.IsMini = true; bool isGeneric = umaContainer.IsGeneric = costumeId.Length >= 4; diff --git a/Assets/Scripts/UmaViewerUI.cs b/Assets/Scripts/UmaViewerUI.cs index 508b59e..9238192 100644 --- a/Assets/Scripts/UmaViewerUI.cs +++ b/Assets/Scripts/UmaViewerUI.cs @@ -380,7 +380,7 @@ public class UmaViewerUI : MonoBehaviour foreach (var prop in extraMorph.BindProperties) { var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent(); - container.Name = $"{morph.locator.name}({prop.Type})"; + container.Name = $"{morph.name}({prop.Type})"; container.Slider.value = prop.Value; switch (prop.Type) { @@ -391,12 +391,12 @@ public class UmaViewerUI : MonoBehaviour break; case BindProperty.BindType.Select: container.Slider.wholeNumbers = true; - container.Slider.maxValue = prop.BindPrefab.Count - 1; + container.Slider.maxValue = prop.BindPrefabs.Count - 1; container.Slider.minValue = 0; break; case BindProperty.BindType.EyeSelect: container.Slider.wholeNumbers = true; - container.Slider.maxValue = prop.BindPrefab.Count / 2 - 1; + container.Slider.maxValue = prop.BindPrefabs.Count / 2 - 1; container.Slider.minValue = 0; break; case BindProperty.BindType.Enable: diff --git a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs index cfa51fe..6c3151d 100644 --- a/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs +++ b/Assets/Scripts/umamusume/Gallop/FaceDrivenKeyTarget.cs @@ -51,6 +51,7 @@ namespace Gallop FacialOtherMorph CheekMorph; FacialOtherMorph ShadeMorph; FacialOtherMorph MangaMorph; + FacialOtherMorph StaticTearMorph; List TearMorphs = new List(); public void Initialize(Dictionary objs) @@ -289,17 +290,43 @@ namespace Gallop { Part = BindProperty.LocatorPart.ScaY, Type = BindProperty.BindType.EyeSelect, - BindPrefab = mangaObjects + BindPrefabs = mangaObjects }); FaceMangaMorph.BindProperties.Add(new BindProperty() { Part = BindProperty.LocatorPart.ScaX, Type = BindProperty.BindType.Enable, - BindPrefab = mangaObjects + BindPrefabs = mangaObjects }); OtherMorphs.Add(FaceMangaMorph); MangaMorph = FaceMangaMorph; + if(Container.StaticTear_L && Container.StaticTear_R) + { + FacialOtherMorph StaticTearMorph = new FacialOtherMorph() + { + name = "StaticTear_Ctrl", + locator = DrivenKeyLocator.Find("Cheek_Ctrl") + }; + + StaticTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.PosX, + Type = BindProperty.BindType.Enable, + BindPrefabs = new List() { Container.StaticTear_L } + }); + + StaticTearMorph.BindProperties.Add(new BindProperty() + { + Part = BindProperty.LocatorPart.PosY, + Type = BindProperty.BindType.Enable, + BindPrefabs = new List() { Container.StaticTear_R } + }); + + this.StaticTearMorph = StaticTearMorph; + OtherMorphs.Add(StaticTearMorph); + } + foreach (var tear in Container.TearControllers) { var index = Container.TearControllers.IndexOf(tear); @@ -499,18 +526,22 @@ namespace Gallop property.BindMaterial.SetFloat(property.PropertyName, property.Value); break; case BindProperty.BindType.Select: - property.BindPrefab.ForEach(a => a.SetActive((int)property.Value == property.BindPrefab.IndexOf(a))); + property.BindPrefabs.ForEach(a => a.SetActive((int)property.Value == property.BindPrefabs.IndexOf(a))); break; case BindProperty.BindType.EyeSelect: - var count = property.BindPrefab.Count / 2; + var count = property.BindPrefabs.Count / 2; var val = (int)property.Value; - property.BindPrefab.ForEach(a => - a.SetActive(val + count < property.BindPrefab.Count && (val == property.BindPrefab.IndexOf(a) || val + count == property.BindPrefab.IndexOf(a)))); + property.BindPrefabs.ForEach(a => + a.SetActive(val + count < property.BindPrefabs.Count && (val == property.BindPrefabs.IndexOf(a) || val + count == property.BindPrefabs.IndexOf(a)))); break; case BindProperty.BindType.Enable: - if (property.Value <= 0) + if(property.BindPrefabs.Count == 1) { - property.BindPrefab.ForEach(a => a.SetActive(false)); + property.BindPrefabs.ForEach(a => a.SetActive(property.Value > 0)); + } + else if(property.Value <= 0) + { + property.BindPrefabs.ForEach(a => a.SetActive(false)); } break; case BindProperty.BindType.TearSide: @@ -942,7 +973,8 @@ namespace Gallop MangaMorph.BindProperties[1].Value = 1; } - //TODO Support Tear effect + var tearytype = info.tearyType; + StaticTearMorph.BindProperties.ForEach(p => p.Value = tearytype); ChangeMorphEffect(); } diff --git a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs index 307703f..5bf3364 100644 --- a/Assets/Scripts/umamusume/Gallop/FacialMorph.cs +++ b/Assets/Scripts/umamusume/Gallop/FacialMorph.cs @@ -35,6 +35,7 @@ namespace Gallop public List BindProperties = new List(); public float GetLocatorValue(BindProperty.LocatorPart part) { + if (!locator) return 0; switch (part) { case BindProperty.LocatorPart.PosX: return locator.localPosition.x; @@ -76,7 +77,7 @@ namespace Gallop public Material BindMaterial; public Texture BindTexture; public TearController BindTearController; - public List BindPrefab = new List(); + public List BindPrefabs = new List(); public string PropertyName; public LocatorPart Part; public BindType Type; diff --git a/Assets/Scripts/umamusume/Gallop/TearController.cs b/Assets/Scripts/umamusume/Gallop/TearController.cs index e68f96c..e9346b5 100644 --- a/Assets/Scripts/umamusume/Gallop/TearController.cs +++ b/Assets/Scripts/umamusume/Gallop/TearController.cs @@ -29,7 +29,7 @@ public class TearController private AssetHolder AssetHolder1; bool intialized; - public TearController(Transform headBone, GameObject tearPrefab_0, GameObject tearPrefab_1, int dir, int currentObject) + public TearController(int id ,Transform headBone, GameObject tearPrefab_0, GameObject tearPrefab_1, int dir, int currentObject) { AttachBone_2_L = headBone.transform.Find("Eye_tear_attach_02_L"); AttachBone_2_R = headBone.transform.Find("Eye_tear_attach_02_R"); @@ -40,6 +40,10 @@ public class TearController AssetHolder0 = TearObject_0.GetComponent(); TearMaterial_0 = TearObject_0.GetComponentInChildren().material; TearMaterial_0.SetFloat("_OffsetFactor", -1000); + TearMaterial_0.SetFloat("_StencilMask", id); + TearMaterial_0.SetFloat("_StencilComp", (float)UnityEngine.Rendering.CompareFunction.Equal); + TearMaterial_0.SetFloat("_StencilOp", (float)UnityEngine.Rendering.StencilOp.Keep); + TearMaterial_0.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest; Animator_0 = TearObject_0.GetComponent(); var clip = AssetHolder0._assetTable["default_animation"] as AnimationClip; var controller = new AnimatorOverrideController(Animator_0.runtimeAnimatorController); @@ -50,6 +54,10 @@ public class TearController AssetHolder1 = TearObject_1.GetComponent(); TearMaterial_1 = TearObject_1.GetComponentInChildren().material; TearMaterial_1.SetFloat("_OffsetFactor", -1000); + TearMaterial_1.SetFloat("_StencilMask", id); + TearMaterial_1.SetFloat("_StencilComp", (float)UnityEngine.Rendering.CompareFunction.Equal); + TearMaterial_1.SetFloat("_StencilOp", (float)UnityEngine.Rendering.StencilOp.Keep); + TearMaterial_1.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest; Animator_1 = TearObject_1.GetComponent(); clip = AssetHolder1._assetTable["default_animation"] as AnimationClip; controller = new AnimatorOverrideController(Animator_1.runtimeAnimatorController);