fix facial stencil problem, add static tear morph

This commit is contained in:
CroakFang
2023-08-31 00:14:14 +08:00
parent 1189922fcc
commit 8b0f738417
6 changed files with 91 additions and 23 deletions
+33 -8
View File
@@ -54,6 +54,8 @@ public class UmaContainerCharacter : UmaContainer
public List<GameObject> RightMangaObject = new List<GameObject>();
[Header("Tear")]
public GameObject StaticTear_L;
public GameObject StaticTear_R;
public GameObject TearPrefab_0;
public GameObject TearPrefab_1;
public List<TearController> TearControllers = new List<TearController>();
@@ -632,6 +634,7 @@ public class UmaContainerCharacter : UmaContainer
var textures = MobHeadTextures;
GameObject head = Instantiate(go, transform);
Head = head;
var table = Head.GetComponent<AssetHolder>()._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<AssetHolder>()._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<Texture>("tex_chr_tear00");
StaticTear_L = table["tearmesh_l"] as GameObject;
StaticTear_R = table["tearmesh_r"] as GameObject;
StaticTear_L.GetComponent<Renderer>().material.mainTexture = tex;
StaticTear_R.GetComponent<Renderer>().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<Renderer>(leftObj.GetComponentsInChildren<Renderer>()).ForEach(a => a.material.renderQueue = -1);
new List<Renderer>(leftObj.GetComponentsInChildren<Renderer>(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<Renderer>(RightObj.GetComponentsInChildren<Renderer>()).ForEach(a => { a.material.renderQueue = -1; });
new List<Renderer>(RightObj.GetComponentsInChildren<Renderer>(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;
+3 -1
View File
@@ -49,7 +49,6 @@ public class UmaViewerBuilder : MonoBehaviour
{
int id = chara.Id;
var umaContainer = new GameObject($"Chara_{id}_{costumeId}").AddComponent<UmaContainerCharacter>();
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;
+3 -3
View File
@@ -380,7 +380,7 @@ public class UmaViewerUI : MonoBehaviour
foreach (var prop in extraMorph.BindProperties)
{
var container = Instantiate(UmaContainerSliderPrefab, TargetList.content).GetComponent<UmaUIContainer>();
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:
@@ -51,6 +51,7 @@ namespace Gallop
FacialOtherMorph CheekMorph;
FacialOtherMorph ShadeMorph;
FacialOtherMorph MangaMorph;
FacialOtherMorph StaticTearMorph;
List<FacialOtherMorph> TearMorphs = new List<FacialOtherMorph>();
public void Initialize(Dictionary<string, Transform> 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<GameObject>() { Container.StaticTear_L }
});
StaticTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.PosY,
Type = BindProperty.BindType.Enable,
BindPrefabs = new List<GameObject>() { 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();
}
@@ -35,6 +35,7 @@ namespace Gallop
public List<BindProperty> BindProperties = new List<BindProperty>();
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<GameObject> BindPrefab = new List<GameObject>();
public List<GameObject> BindPrefabs = new List<GameObject>();
public string PropertyName;
public LocatorPart Part;
public BindType Type;
@@ -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<AssetHolder>();
TearMaterial_0 = TearObject_0.GetComponentInChildren<SkinnedMeshRenderer>().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<Animator>();
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<AssetHolder>();
TearMaterial_1 = TearObject_1.GetComponentInChildren<SkinnedMeshRenderer>().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<Animator>();
clip = AssetHolder1._assetTable["default_animation"] as AnimationClip;
controller = new AnimatorOverrideController(Animator_1.runtimeAnimatorController);