This commit is contained in:
1605296300@qq.com
2022-08-23 01:40:49 +08:00
parent 8140526517
commit 44f72bed20
4 changed files with 122 additions and 171 deletions
+1
View File
@@ -401,6 +401,7 @@ public class UmaViewerBuilder : MonoBehaviour
AnimationClip bbb = asset as AnimationClip; AnimationClip bbb = asset as AnimationClip;
bbb.wrapMode = WrapMode.Loop; bbb.wrapMode = WrapMode.Loop;
CurrentContainer.OverrideController["clip"] = bbb; CurrentContainer.OverrideController["clip"] = bbb;
CurrentContainer.UmaAnimator.Play("clip", 0, 0); CurrentContainer.UmaAnimator.Play("clip", 0, 0);
UnloadBundle(bundle, false); UnloadBundle(bundle, false);
} }
@@ -95,7 +95,7 @@ namespace Gallop
dynamic.SetupParticles(); dynamic.SetupParticles();
dynamic.m_Gravity = new Vector3(0, -spring._gravity / 80000, 0); dynamic.m_Gravity = new Vector3(0, -spring._gravity / 80000, 0);
dynamic.m_Damping = 0.2f; dynamic.m_Damping = 0.2f;
dynamic.m_Stiffness = spring._stiffnessForce / 8000; dynamic.m_Stiffness = spring._stiffnessForce / 1000;
dynamic.m_Elasticity = spring._dragForce / 4000; dynamic.m_Elasticity = spring._dragForce / 4000;
dynamic.m_Radius = spring._collisionRadius; dynamic.m_Radius = spring._collisionRadius;
foreach (string collisionName in spring._collisionNameList) foreach (string collisionName in spring._collisionNameList)
@@ -111,7 +111,7 @@ namespace Gallop
if (tempParticle != null) if (tempParticle != null)
{ {
tempParticle.m_Damping = 0.2f; tempParticle.m_Damping = 0.2f;
tempParticle.m_Stiffness = Childcollision._stiffnessForce / 8000; tempParticle.m_Stiffness = Childcollision._stiffnessForce / 1000;
tempParticle.m_Elasticity = Childcollision._dragForce / 4000; tempParticle.m_Elasticity = Childcollision._dragForce / 4000;
tempParticle.m_Radius = Childcollision._collisionRadius; tempParticle.m_Radius = Childcollision._collisionRadius;
foreach (string collisionName in Childcollision._collisionNameList) foreach (string collisionName in Childcollision._collisionNameList)
+100 -156
View File
@@ -12,9 +12,9 @@ namespace Gallop
public List<MouthTarget> _mouthTarget; public List<MouthTarget> _mouthTarget;
public List<Transform> Objs = new List<Transform>(); public List<Transform> Objs = new List<Transform>();
private List<Vector3> OriTrans = new List<Vector3>(); private FacialMorph BaseLEyeBrowMorph, BaseREyeBrowMorph;
private List<Quaternion> OriRots = new List<Quaternion>(); private FacialMorph BaseLEyeMorph, BaseREyeMorph;
private List<Vector3> OriScal = new List<Vector3>(); private FacialMorph BaseMouthMorph;
public List<FacialMorph> EyeBrowMorphs = new List<FacialMorph>(); public List<FacialMorph> EyeBrowMorphs = new List<FacialMorph>();
public List<FacialMorph> EyeMorphs = new List<FacialMorph>(); public List<FacialMorph> EyeMorphs = new List<FacialMorph>();
@@ -25,26 +25,29 @@ namespace Gallop
{ {
Objs.AddRange(GetComponentsInChildren<Transform>()); Objs.AddRange(GetComponentsInChildren<Transform>());
foreach (Transform g in Objs)
{
OriTrans.Add(g.localPosition);
OriRots.Add(g.localRotation);
OriScal.Add(g.localScale);
}
for (int i = 0; i < _eyebrowTarget.Count; i++) for (int i = 0; i < _eyebrowTarget.Count; i++)
{ {
for (int j = 0; j < _eyebrowTarget[i]._faceGroupInfo.Count; j++) for (int j = 0; j < _eyebrowTarget[i]._faceGroupInfo.Count; j++)
{ {
FacialMorph morph = new FacialMorph(); FacialMorph morph = new FacialMorph();
morph.SetFace(this); morph.target = this;
morph.name = "EyeBrow_" + i + "_" + (j > 0 ? "R" : "L"); morph.direction = j > 0;
morph.name = "EyeBrow_" + i + "_" + (morph.direction ? "R" : "L");
morph.trsArray = _eyebrowTarget[i]._faceGroupInfo[j]._trsArray; morph.trsArray = _eyebrowTarget[i]._faceGroupInfo[j]._trsArray;
foreach(TrsArray trs in morph.trsArray) foreach (TrsArray trs in morph.trsArray)
{ {
trs.transform = Objs.Find(ani => ani.name.Equals(trs._path)); trs.transform = Objs.Find(ani => ani.name.Equals(trs._path));
} }
EyeBrowMorphs.Add(morph); if (i == 0)
{
if (morph.direction) BaseREyeBrowMorph = morph;
else BaseLEyeBrowMorph = morph;
}
else
{
EyeBrowMorphs.Add(morph);
}
} }
} }
@@ -53,14 +56,23 @@ namespace Gallop
for (int j = 0; j < _eyeTarget[i]._faceGroupInfo.Count; j++) for (int j = 0; j < _eyeTarget[i]._faceGroupInfo.Count; j++)
{ {
FacialMorph morph = new FacialMorph(); FacialMorph morph = new FacialMorph();
morph.SetFace(this); morph.target = this;
morph.name = "Eye_" + i + "_" + (j > 0 ? "R" : "L"); morph.direction = j > 0;
morph.name = "Eye_" + i + "_" + (morph.direction ? "R" : "L");
morph.trsArray = _eyeTarget[i]._faceGroupInfo[j]._trsArray; morph.trsArray = _eyeTarget[i]._faceGroupInfo[j]._trsArray;
foreach (TrsArray trs in morph.trsArray) foreach (TrsArray trs in morph.trsArray)
{ {
trs.transform = Objs.Find(ani => ani.name.Equals(trs._path)); trs.transform = Objs.Find(ani => ani.name.Equals(trs._path));
} }
EyeMorphs.Add(morph); if (i == 0)
{
if (morph.direction) BaseREyeMorph = morph;
else BaseLEyeMorph = morph;
}
else
{
EyeMorphs.Add(morph);
}
} }
} }
@@ -69,179 +81,111 @@ namespace Gallop
for (int j = 0; j < _mouthTarget[i]._faceGroupInfo.Count; j++) for (int j = 0; j < _mouthTarget[i]._faceGroupInfo.Count; j++)
{ {
FacialMorph morph = new FacialMorph(); FacialMorph morph = new FacialMorph();
morph.SetFace(this); morph.target = this;
morph.direction = j > 0;
morph.name = "Mouth_" + i + "_" + j; morph.name = "Mouth_" + i + "_" + j;
morph.trsArray = _mouthTarget[i]._faceGroupInfo[j]._trsArray; morph.trsArray = _mouthTarget[i]._faceGroupInfo[j]._trsArray;
foreach (TrsArray trs in morph.trsArray) foreach (TrsArray trs in morph.trsArray)
{ {
trs.transform = Objs.Find(ani => ani.name.Equals(trs._path)); trs.transform = Objs.Find(ani => ani.name.Equals(trs._path));
} }
MouthMorphs.Add(morph); if (i == 0)
{
BaseMouthMorph = morph;
}
else
{
MouthMorphs.Add(morph);
}
} }
} }
FacialReset();
MouthMorphs[4].Weight = 1; MouthMorphs[3].Weight = 1;
if (callBack != null) { callBack.CallBack(this); } if (callBack != null) { callBack.CallBack(this); }
} }
private void FixedUpdate()
{
bool changed = false;
for (int i = 0; i < EyeBrowMorphs.Count; i++)
{
if(EyeBrowMorphs[i].LastWeight!= EyeBrowMorphs[i].Weight)
{
changed = true;
}
}
for (int i = 0; i < EyeMorphs.Count; i++)
{
if (EyeMorphs[i].LastWeight != EyeMorphs[i].Weight)
{
changed = true;
}
}
for (int i = 0; i < MouthMorphs.Count; i++)
{
if (MouthMorphs[i].LastWeight != MouthMorphs[i].Weight)
{
changed = true;
}
}
if (changed)ChangeMorph();
}
public void ChangeMorph() public void ChangeMorph()
{ {
FacialReset(); FacialReset();
foreach (FacialMorph morph in EyeBrowMorphs) foreach (FacialMorph morph in EyeBrowMorphs)
{ {
if(morph.LastWeight!=morph.Weight || morph.Weight > 0) ProcessMorph(morph);
foreach(TrsArray trs in morph.trsArray)
{
if (trs.transform)
{
if (!trs.IsOverrideTarget)
{
var tmp = trs.transform.localRotation.eulerAngles;
tmp += (trs._rotation * morph.Weight);
trs.transform.localRotation = Quaternion.Euler(trs.transform.localRotation.eulerAngles + (trs._rotation * morph.Weight));
trs.transform.localPosition += trs._position * morph.Weight;
trs.transform.localScale += trs._scale * morph.Weight;
}
};
}
} }
foreach (FacialMorph morph in EyeMorphs) foreach (FacialMorph morph in EyeMorphs)
{ {
if(morph.LastWeight!=morph.Weight || morph.Weight > 0) ProcessMorph(morph);
foreach (TrsArray trs in morph.trsArray)
{
if (trs.transform)
{
if (!trs.IsOverrideTarget)
{
var tmp = trs.transform.localRotation.eulerAngles;
tmp += (trs._rotation * morph.Weight);
trs.transform.localRotation = Quaternion.Euler(trs.transform.localRotation.eulerAngles + (trs._rotation * morph.Weight));
trs.transform.localPosition += trs._position * morph.Weight;
trs.transform.localScale += trs._scale * morph.Weight;
}
};
}
} }
foreach (FacialMorph morph in MouthMorphs) foreach (FacialMorph morph in MouthMorphs)
{ {
if(morph.LastWeight!=morph.Weight || morph.Weight > 0) ProcessMorph(morph);
foreach (TrsArray trs in morph.trsArray)
{
if (trs.transform)
{
if (!trs.IsOverrideTarget)
{
var tmp = trs.transform.localRotation.eulerAngles;
tmp += (trs._rotation * morph.Weight);
trs.transform.localRotation = Quaternion.Euler(trs.transform.localRotation.eulerAngles + (trs._rotation * morph.Weight));
trs.transform.localPosition += trs._position * morph.Weight;
trs.transform.localScale += trs._scale * morph.Weight;
}
};
}
} }
}
private void ProcessMorph(FacialMorph morph)
foreach (FacialMorph morph in EyeBrowMorphs)//´¦Àí¸²¸Ç±íÇé {
foreach (TrsArray trs in morph.trsArray)
{ {
if (morph.LastWeight != morph.Weight || morph.Weight > 0) if (trs.transform)
{ {
foreach (TrsArray trs in morph.trsArray) trs.transform.localRotation = Quaternion.Euler(trs.transform.localRotation.eulerAngles + (trs._rotation * morph.Weight));
{ trs.transform.localPosition += trs._position * morph.Weight;
if (trs.transform) trs.transform.localScale += trs._scale * morph.Weight;
{ };
if (trs.IsOverrideTarget)
{
trs.transform.localRotation = Quaternion.Euler(Vector3.Lerp(trs.transform.localRotation.eulerAngles, trs._rotation, morph.Weight));
trs.transform.localPosition = Vector3.Lerp(trs.transform.localPosition, trs._position, morph.Weight);
trs.transform.localScale = Vector3.Lerp(trs.transform.localScale, trs._scale, morph.Weight);
}
};
}
morph.LastWeight = morph.Weight;
}
}
foreach (FacialMorph morph in EyeMorphs)
{
if (morph.LastWeight != morph.Weight || morph.Weight > 0)
{
foreach (TrsArray trs in morph.trsArray)
{
if (trs.transform)
{
if (trs.IsOverrideTarget)
{
trs.transform.localRotation = Quaternion.Euler(Vector3.Lerp(trs.transform.localRotation.eulerAngles, trs._rotation, morph.Weight));
trs.transform.localPosition = Vector3.Lerp(trs.transform.localPosition, trs._position, morph.Weight);
trs.transform.localScale = Vector3.Lerp(trs.transform.localScale, trs._scale, morph.Weight);
}
};
}
morph.LastWeight = morph.Weight;
}
}
foreach (FacialMorph morph in MouthMorphs)
{
if (morph.LastWeight != morph.Weight || morph.Weight > 0)
{
foreach (TrsArray trs in morph.trsArray)
{
if (trs.transform)
{
if (trs.IsOverrideTarget)
{
trs.transform.localRotation = Quaternion.Euler(Vector3.Lerp(trs.transform.localRotation.eulerAngles, trs._rotation, morph.Weight));
trs.transform.localPosition = Vector3.Lerp(trs.transform.localPosition, trs._position, morph.Weight);
trs.transform.localScale = Vector3.Lerp(trs.transform.localScale, trs._scale, morph.Weight);
}
};
}
morph.LastWeight = morph.Weight;
}
} }
} }
public void FacialReset() public void FacialReset()
{ {
for (int i = 0; i < Objs.Count; i++) foreach (TrsArray trs in BaseLEyeBrowMorph.trsArray)
{ {
Objs[i].localPosition = OriTrans[i]; if (trs.transform)
Objs[i].localRotation = OriRots[i]; {
Objs[i].localScale = OriScal[i]; trs.transform.localRotation = Quaternion.Euler(trs._rotation);
trs.transform.localPosition = trs._position;
trs.transform.localScale = trs._scale;
};
}
foreach (TrsArray trs in BaseREyeBrowMorph.trsArray)
{
if (trs.transform)
{
trs.transform.localRotation = Quaternion.Euler(trs._rotation);
trs.transform.localPosition = trs._position;
trs.transform.localScale = trs._scale;
};
}
foreach (TrsArray trs in BaseLEyeMorph.trsArray)
{
if (trs.transform)
{
trs.transform.localRotation = Quaternion.Euler(trs._rotation);
trs.transform.localPosition = trs._position;
trs.transform.localScale = trs._scale;
};
}
foreach (TrsArray trs in BaseREyeMorph.trsArray)
{
if (trs.transform)
{
trs.transform.localRotation = Quaternion.Euler(trs._rotation);
trs.transform.localPosition = trs._position;
trs.transform.localScale = trs._scale;
};
}
foreach (TrsArray trs in BaseMouthMorph.trsArray)
{
if (trs.transform)
{
trs.transform.localRotation = Quaternion.Euler(trs._rotation);
trs.transform.localPosition = trs._position;
trs.transform.localScale = trs._scale;
};
} }
} }
+15 -9
View File
@@ -11,15 +11,21 @@ namespace Gallop
public class FacialMorph public class FacialMorph
{ {
public string name; public string name;
private FaceDrivenKeyTarget face; public bool direction;
[Range(0, 1)] public FaceDrivenKeyTarget target;
public float Weight; private float _weight;
[HideInInspector]public float LastWeight; public float Weight
[HideInInspector] public List<TrsArray> trsArray;
public void SetFace(FaceDrivenKeyTarget faceTarget)
{ {
face = faceTarget; get
} {
return _weight;
}
set
{
_weight = value;
target.ChangeMorph();
}
}
[HideInInspector] public List<TrsArray> trsArray;
} }
} }