Add other facial morph support ,bug fix

This commit is contained in:
CroakFang
2022-11-20 17:57:09 +08:00
parent 433cf64a01
commit de0c02e755
8 changed files with 324 additions and 89 deletions
@@ -258,10 +258,49 @@ namespace Gallop
FaceMangaMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.Bool,
Type = BindProperty.BindType.Enable,
BindPrefab = mangaObjects
});
OtherMorphs.Add(FaceMangaMorph);
foreach(var tear in Container.TearControllers)
{
var index = Container.TearControllers.IndexOf(tear);
FacialExtraMorph FaceTearMorph = new FacialExtraMorph()
{
name = $"Tear{index}_Ctrl",
locator = DrivenKeyLocator.Find($"Tear{index}_Ctrl")
};
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaX,
Type = BindProperty.BindType.TearWeight,
BindTearController = tear,
Value = tear.Weight
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.PosY,
Type = BindProperty.BindType.TearSide,
BindTearController = tear,
Value = tear.CurrentDir
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaY,
Type = BindProperty.BindType.TearSelect,
BindTearController = tear,
Value = tear.CurrenObject
});
FaceTearMorph.BindProperties.Add(new BindProperty()
{
Part = BindProperty.LocatorPart.ScaZ,
Type = BindProperty.BindType.TearSpeed,
BindTearController = tear,
Value = tear.Speed
});
OtherMorphs.Add(FaceTearMorph);
}
}
public void SetupAnimator()
@@ -380,12 +419,24 @@ namespace Gallop
property.BindPrefab.ForEach(a =>
a.SetActive(val + count < property.BindPrefab.Count && (val == property.BindPrefab.IndexOf(a) || val + count == property.BindPrefab.IndexOf(a))));
break;
case BindProperty.BindType.Bool:
case BindProperty.BindType.Enable:
if (property.Value <= 0)
{
property.BindPrefab.ForEach(a =>a.SetActive(false));
}
break;
case BindProperty.BindType.TearSide:
property.BindTearController.SetDir((int)property.Value);
break;
case BindProperty.BindType.TearWeight:
property.BindTearController.SetWegiht(property.Value);
break;
case BindProperty.BindType.TearSelect:
property.BindTearController.SetObject((int)property.Value);
break;
case BindProperty.BindType.TearSpeed:
property.BindTearController.SetSpeed(property.Value);
break;
}
}
}
@@ -491,12 +542,6 @@ namespace Gallop
}
});
LeftEyeXrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
RightEyeXrange.weight = -(EyeballCtrl_R_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
LeftEyeYrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
RightEyeYrange.weight = (EyeballCtrl_R_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
OtherMorphs.ForEach(morph =>
{
morph.BindProperties.ForEach(property =>
@@ -505,12 +550,19 @@ namespace Gallop
});
});
LeftEyeXrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
RightEyeXrange.weight = -(EyeballCtrl_R_Locator.transform.localPosition.x * -100 + EyeballCtrl_All_Locator.transform.localPosition.x * -100);
LeftEyeYrange.weight = -(EyeballCtrl_L_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
RightEyeYrange.weight = (EyeballCtrl_R_Locator.transform.localPosition.y * -100 + EyeballCtrl_All_Locator.transform.localPosition.y * -100);
ChangeMorph();
}
public void ResetLocator()
{
Container.UmaFaceAnimator.Rebind();
ProcessLocator();
ChangeMorph();
}
}
@@ -57,10 +57,15 @@ namespace Gallop
Select,
EyeSelect,
Texture,
Bool
Enable,
TearSide,
TearWeight,
TearSelect,
TearSpeed
}
public Material BindMaterial;
public Texture BindTexture;
public TearController BindTearController;
public List<GameObject> BindPrefab = new List<GameObject>();
public string PropertyName;
public LocatorPart Part;
@@ -0,0 +1,148 @@
using Gallop;
using UnityEngine;
public class TearController
{
public GameObject TearObject_0;
public GameObject TearObject_1;
public Material CurrentMaterial;
public Material TearMaterial_0;
public Material TearMaterial_1;
public int CurrenObject;
public int CurrentDir;
public float Weight;
public float Speed = 1;
private Animator CurrentAnimator;
private Animator Animator_0;
private Animator Animator_1;
private Transform AttachBone_2_L;
private Transform AttachBone_2_R;
private Transform AttachBone_3_L;
private Transform AttachBone_3_R;
private AssetHolder CurrentAssetHolder;
private AssetHolder AssetHolder0;
private AssetHolder AssetHolder1;
bool intialized;
public TearController(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");
AttachBone_3_L = headBone.transform.Find("Eye_tear_attach_03_L");
AttachBone_3_R = headBone.transform.Find("Eye_tear_attach_03_R");
TearObject_0 = tearPrefab_0;
AssetHolder0 = TearObject_0.GetComponent<AssetHolder>();
TearMaterial_0 = TearObject_0.GetComponentInChildren<SkinnedMeshRenderer>().material;
Animator_0 = TearObject_0.GetComponent<Animator>();
var clip = AssetHolder0._assetTable["default_animation"] as AnimationClip;
var controller = new AnimatorOverrideController(Animator_0.runtimeAnimatorController);
controller["anm_tear000_00"] = clip;
Animator_0.runtimeAnimatorController = controller;
TearObject_1 = tearPrefab_1;
AssetHolder1 = TearObject_1.GetComponent<AssetHolder>();
TearMaterial_1 = TearObject_1.GetComponentInChildren<SkinnedMeshRenderer>().material;
Animator_1 = TearObject_1.GetComponent<Animator>();
clip = AssetHolder1._assetTable["default_animation"] as AnimationClip;
controller = new AnimatorOverrideController(Animator_1.runtimeAnimatorController);
controller["anm_tear000_00"] = clip;
Animator_1.runtimeAnimatorController = controller;
SetWegiht(0);
SetDir(dir);
SetObject(currentObject);
intialized = true;
}
public void SetDir(int dir)
{
if (intialized && ((dir > 0 && CurrentDir > 0) || (dir <= 0 && CurrentDir <= 0))) return;
CurrentDir = dir;
if (dir > 0)//RightEye
{
TearObject_0.transform.position = AttachBone_3_R.position + AttachBone_3_R.forward * 0.004f;
TearObject_1.transform.position = AttachBone_2_R.position + AttachBone_2_R.forward * 0.004f;
TearObject_0.transform.localScale = new Vector3(-1, 1, 1);
TearObject_1.transform.localScale = new Vector3(-1, 1, 1);
}
else//LeftEye
{
TearObject_0.transform.position = AttachBone_3_L.position + AttachBone_3_L.forward * 0.004f;
TearObject_1.transform.position = AttachBone_2_L.position + AttachBone_2_L.forward * 0.004f;
TearObject_0.transform.localScale = new Vector3(1, 1, 1);
TearObject_1.transform.localScale = new Vector3(1, 1, 1);
}
}
public void SetObject(int curObject)
{
if (intialized && ((curObject < 1 && CurrenObject < 1) || (curObject >= 1 && CurrenObject >= 1))) return;
CurrenObject = curObject;
CurrentAnimator = (curObject < 1) ? Animator_0 : Animator_1;
CurrentMaterial = (curObject < 1) ? TearMaterial_0 : TearMaterial_1;
CurrentAssetHolder = (curObject < 1) ? AssetHolder0 : AssetHolder1;
if (Weight > 0)
{
TearObject_0.SetActive(curObject < 1);
TearObject_1.SetActive(curObject >= 1);
}
}
public void SetWegiht(float weight)
{
if (intialized && (weight <= 0 && Weight <= 0)) return;
Weight = weight;
if (weight <= 0)
{
TearObject_0.SetActive(false);
TearObject_1.SetActive(false);
}
else
{
TearObject_0.SetActive(CurrenObject < 1);
TearObject_1.SetActive(CurrenObject >= 1);
}
}
public void SetSpeed(float speed)
{
if (speed == Speed) return;
Speed = speed;
Animator_0.speed = speed;
Animator_1.speed = speed;
}
public void UpdateOffset()
{
if (Weight <= 0) return;
var time = Mathf.Repeat(CurrentAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime,1);
var width = (int)CurrentAssetHolder._assetTableValue["texture_width"];
var height = (int)CurrentAssetHolder._assetTableValue["texture_height"];
var partWidth = (int)CurrentAssetHolder._assetTableValue["texture_part_width"];
var partHeight = (int)CurrentAssetHolder._assetTableValue["texture_part_height"];
var offset = GetTextureOffset(time, width, height, partWidth, partHeight);
CurrentMaterial.SetColor("_TexScrollParam", new Color(offset.x, -offset.y, 0, Weight));
}
private Vector2 GetTextureOffset(float time,int w,int h,int pw ,int ph)
{
int wCount = w / pw;
int hCount = h / ph;
int index = (int)(time * (wCount * hCount));
return new Vector2((index % wCount) / (float)wCount,(index/wCount)/(float)hCount);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 52416b72680489b4a9a3b590b739e09a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: