Add ear morph with physics support
This commit is contained in:
@@ -2,6 +2,7 @@ using Gallop.Live.Cutt;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static DynamicBone;
|
||||
|
||||
namespace Gallop
|
||||
{
|
||||
@@ -25,15 +26,25 @@ namespace Gallop
|
||||
public List<FacialMorph> MouthMorphs = new List<FacialMorph>();
|
||||
|
||||
public GameObject DrivenKeyLocator;
|
||||
public GameObject EyeballCtrl_L_Locator, EyeballCtrl_R_Locator, EyeballCtrl_All_Locator;
|
||||
|
||||
public UmaContainer Container;
|
||||
|
||||
Dictionary<Transform, Vector3> RotationRecorder = new Dictionary<Transform, Vector3>();
|
||||
|
||||
Dictionary<Particle, Vector3> ParticleRecorder = new Dictionary<Particle, Vector3>();
|
||||
public void Initialize(List<Transform> objs)
|
||||
{
|
||||
Objs = objs;
|
||||
|
||||
List<Particle> particles = new List<Particle>();
|
||||
foreach (CySpringDataContainer spring in Container.cySpringDataContainers)
|
||||
{
|
||||
foreach (DynamicBone dynamicBone in spring.DynamicBones)
|
||||
{
|
||||
particles.AddRange(dynamicBone.Particles);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _earTarget.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < _earTarget[i]._faceGroupInfo.Count; j++)
|
||||
@@ -46,6 +57,12 @@ namespace Gallop
|
||||
morph.trsArray = _earTarget[i]._faceGroupInfo[j]._trsArray;
|
||||
foreach (TrsArray trs in morph.trsArray)
|
||||
{
|
||||
var physicsParticle = particles.Find(a => a.m_Transform.name.Equals(trs._path));
|
||||
if (physicsParticle != null)
|
||||
{
|
||||
trs.isPhysics = true;
|
||||
trs.physicsParticle = physicsParticle;
|
||||
}
|
||||
trs.transform = Objs.Find(ani => ani.name.Equals(trs._path));
|
||||
}
|
||||
if (i == 0)
|
||||
@@ -147,7 +164,7 @@ namespace Gallop
|
||||
}
|
||||
}
|
||||
}
|
||||
FacialResetAll();
|
||||
|
||||
ChangeMorphWeight(MouthMorphs[3], 1);
|
||||
SetupAnimator();
|
||||
if (UmaViewerUI.Instance)
|
||||
@@ -160,12 +177,26 @@ namespace Gallop
|
||||
{
|
||||
DrivenKeyLocator = new GameObject("DrivenKeyLocator");
|
||||
DrivenKeyLocator.transform.SetParent(Container.transform);
|
||||
SetupLocator("Ear_L_Ctrl", "Ear_L__", EarMorphs.FindAll(a => a.direction == true));
|
||||
SetupLocator("Ear_R_Ctrl", "Ear_R__", EarMorphs.FindAll(a => a.direction == false));
|
||||
SetupLocator("Eye_L_Base_Ctrl", "Eye_L__", EyeMorphs.FindAll(a => a.direction == true));
|
||||
SetupLocator("Eye_R_Base_Ctrl", "Eye_R__", EyeMorphs.FindAll(a => a.direction == false));
|
||||
SetupLocator("Eyebrow_L_Base_Ctrl", "Eyebrow_L__", EyeBrowMorphs.FindAll(a => a.direction == true));
|
||||
SetupLocator("Eyebrow_R_Base_Ctrl", "Eyebrow_R__", EyeBrowMorphs.FindAll(a => a.direction == false));
|
||||
SetupLocator("Mouth_Base_Ctrl", "Mouth__", MouthMorphs.FindAll(a => a.direction == false));
|
||||
|
||||
var root = new GameObject("Eyeball_L_Ctrl");
|
||||
root.transform.SetParent(DrivenKeyLocator.transform);
|
||||
EyeballCtrl_L_Locator = root;
|
||||
|
||||
root = new GameObject("Eyeball_R_Ctrl");
|
||||
root.transform.SetParent(DrivenKeyLocator.transform);
|
||||
EyeballCtrl_R_Locator = root;
|
||||
|
||||
root = new GameObject("Eyeball_all_Ctrl");
|
||||
root.transform.SetParent(DrivenKeyLocator.transform);
|
||||
EyeballCtrl_All_Locator = root;
|
||||
|
||||
Container.UmaFaceAnimator = DrivenKeyLocator.AddComponent<Animator>();
|
||||
Container.UmaFaceAnimator.avatar = AvatarBuilder.BuildGenericAvatar(DrivenKeyLocator, "DrivenKeyLocator");
|
||||
Container.FaceOverrideController = Instantiate(UmaViewerBuilder.Instance.FaceOverrideController);
|
||||
@@ -177,8 +208,9 @@ namespace Gallop
|
||||
var root = new GameObject(rootName);
|
||||
root.transform.SetParent(DrivenKeyLocator.transform);
|
||||
|
||||
morphs.ForEach(morph=>{
|
||||
var locator = new GameObject(prefix+morph.tag);
|
||||
morphs.ForEach(morph =>
|
||||
{
|
||||
var locator = new GameObject(prefix + morph.tag);
|
||||
locator.transform.SetParent(root.transform);
|
||||
morph.locator = locator.transform;
|
||||
});
|
||||
@@ -213,7 +245,6 @@ namespace Gallop
|
||||
|
||||
public void ClearMorph()
|
||||
{
|
||||
|
||||
foreach (FacialMorph morph in EarMorphs)
|
||||
{
|
||||
morph.weight = 0;
|
||||
@@ -239,12 +270,17 @@ namespace Gallop
|
||||
{
|
||||
foreach (TrsArray trs in morph.trsArray)
|
||||
{
|
||||
if (trs.transform)
|
||||
if (trs.isPhysics && Container.EnablePhysics)
|
||||
{
|
||||
trs.physicsParticle.m_InitLocalPosition += trs._position * morph.weight;
|
||||
ParticleRecorder[trs.physicsParticle] += trs._rotation * morph.weight;
|
||||
}
|
||||
else if(trs.transform)
|
||||
{
|
||||
trs.transform.localScale += trs._scale * morph.weight;
|
||||
trs.transform.localPosition += trs._position * morph.weight;
|
||||
RotationRecorder[trs.transform] += trs._rotation * morph.weight;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,12 +300,17 @@ namespace Gallop
|
||||
{
|
||||
foreach (TrsArray trs in trsArrays)
|
||||
{
|
||||
if (trs.transform)
|
||||
if (trs.isPhysics && Container.EnablePhysics)
|
||||
{
|
||||
trs.physicsParticle.m_InitLocalPosition = trs._position;
|
||||
ParticleRecorder[trs.physicsParticle] = trs._rotation;
|
||||
}
|
||||
else if (trs.transform)
|
||||
{
|
||||
trs.transform.localPosition = trs._position;
|
||||
trs.transform.localScale = trs._scale;
|
||||
RotationRecorder[trs.transform] = trs._rotation;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,18 +318,25 @@ namespace Gallop
|
||||
{
|
||||
foreach (var trs in RotationRecorder)
|
||||
{
|
||||
trs.Key.localRotation = RotationConvert.fromMaya(trs.Value);
|
||||
trs.Key.transform.localRotation = RotationConvert.fromMaya(trs.Value);
|
||||
}
|
||||
if (Container.EnablePhysics)
|
||||
{
|
||||
foreach (var particle in ParticleRecorder)
|
||||
{
|
||||
particle.Key.m_InitLocalRotation = RotationConvert.fromMaya(particle.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeMorphWeight(FacialMorph morph,float val)
|
||||
public void ChangeMorphWeight(FacialMorph morph, float val)
|
||||
{
|
||||
Container.isAnimatorControl = false;
|
||||
morph.weight = val;
|
||||
ChangeMorph();
|
||||
}
|
||||
|
||||
public void SetEyeRange(float lx, float ly,float rx, float ry)
|
||||
|
||||
public void SetEyeRange(float lx, float ly, float rx, float ry)
|
||||
{
|
||||
LeftEyeXrange.weight = lx;
|
||||
LeftEyeYrange.weight = ly;
|
||||
@@ -303,44 +351,64 @@ namespace Gallop
|
||||
{
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
});
|
||||
EyeMorphs.ForEach(morph =>
|
||||
|
||||
EarMorphs.ForEach(morph =>
|
||||
{
|
||||
if (morph == LeftEyeXrange || morph == LeftEyeYrange || morph == RightEyeXrange || morph == RightEyeYrange)
|
||||
{
|
||||
if (!Container.EnableEyeTracking)
|
||||
{
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
}
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
});
|
||||
|
||||
MouthMorphs.ForEach(morph =>
|
||||
{
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
});
|
||||
|
||||
EyeMorphs.ForEach(morph =>
|
||||
{
|
||||
if (!(morph == LeftEyeXrange || morph == LeftEyeYrange || morph == RightEyeXrange || morph == RightEyeYrange))
|
||||
{
|
||||
morph.weight = morph.locator.transform.localPosition.x * -100;
|
||||
}
|
||||
});
|
||||
|
||||
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()
|
||||
{
|
||||
EarMorphs.ForEach(morph =>
|
||||
{
|
||||
morph.weight = 0;
|
||||
morph.locator.transform.localPosition = Vector3.zero;
|
||||
});
|
||||
|
||||
EyeBrowMorphs.ForEach(morph =>
|
||||
{
|
||||
morph.weight = 0;
|
||||
morph.locator.transform.localPosition = Vector3.zero;
|
||||
});
|
||||
|
||||
EyeMorphs.ForEach(morph =>
|
||||
{
|
||||
morph.weight = 0;
|
||||
morph.locator.transform.localPosition = Vector3.zero;
|
||||
});
|
||||
|
||||
MouthMorphs.ForEach(morph =>
|
||||
{
|
||||
morph.weight = 0;
|
||||
morph.locator.transform.localPosition = Vector3.zero;
|
||||
});
|
||||
|
||||
|
||||
EyeballCtrl_L_Locator.transform.localPosition = Vector3.zero;
|
||||
EyeballCtrl_R_Locator.transform.localPosition = Vector3.zero;
|
||||
EyeballCtrl_All_Locator.transform.localPosition = Vector3.zero;
|
||||
ChangeMorph();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user