Add ear morph with physics support
This commit is contained in:
@@ -248,11 +248,11 @@ public class CameraOrbit : MonoBehaviour
|
||||
private void MobileOrbitLight()
|
||||
{
|
||||
return;
|
||||
if (Input.touchCount == 2 && !eventSystem.IsPointerOverGameObject(Input.touches[0].fingerId) && !eventSystem.IsPointerOverGameObject(Input.touches[1].fingerId))
|
||||
{
|
||||
Light.transform.Rotate(Input.GetAxis("Mouse X") * Vector3.up, Space.Self);
|
||||
Light.transform.Rotate(Input.GetAxis("Mouse Y") * Vector3.right, Space.Self);
|
||||
}
|
||||
//if (Input.touchCount == 2 && !eventSystem.IsPointerOverGameObject(Input.touches[0].fingerId) && !eventSystem.IsPointerOverGameObject(Input.touches[1].fingerId))
|
||||
//{
|
||||
// Light.transform.Rotate(Input.GetAxis("Mouse X") * Vector3.up, Space.Self);
|
||||
// Light.transform.Rotate(Input.GetAxis("Mouse Y") * Vector3.right, Space.Self);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -14,12 +14,13 @@ public class UmaContainer : MonoBehaviour
|
||||
public GameObject PhysicsController;
|
||||
|
||||
public List<Texture2D> TailTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Animator")]
|
||||
public Animator UmaAnimator;
|
||||
public AnimatorOverrideController OverrideController;
|
||||
|
||||
public bool isAnimatorControl;
|
||||
public Animator UmaFaceAnimator;
|
||||
public AnimatorOverrideController FaceOverrideController;
|
||||
public bool isAnimatorControl;
|
||||
|
||||
[Header("Face")]
|
||||
public FaceDrivenKeyTarget FaceDrivenKeyTarget;
|
||||
@@ -38,6 +39,10 @@ public class UmaContainer : MonoBehaviour
|
||||
public bool IsMini = false;
|
||||
public List<Texture2D> MiniHeadTextures = new List<Texture2D>();
|
||||
|
||||
[Header("Physics")]
|
||||
public bool EnablePhysics = true;
|
||||
public List<CySpringDataContainer> cySpringDataContainers;
|
||||
|
||||
public void MergeModel()
|
||||
{
|
||||
if (!Body) return;
|
||||
@@ -127,16 +132,28 @@ public class UmaContainer : MonoBehaviour
|
||||
|
||||
public void LoadPhysics()
|
||||
{
|
||||
cySpringDataContainers = new List<CySpringDataContainer>();
|
||||
var springs = PhysicsController.GetComponentsInChildren<CySpringDataContainer>();
|
||||
foreach (CySpringDataContainer spring in springs)
|
||||
{
|
||||
cySpringDataContainers.Add(spring);
|
||||
spring.InitializePhysics();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDynamicBoneEnable(bool isOn)
|
||||
{
|
||||
if (IsMini) return;
|
||||
EnablePhysics = isOn;
|
||||
foreach (CySpringDataContainer cySpring in cySpringDataContainers)
|
||||
{
|
||||
cySpring.EnablePhysics(isOn);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (TrackTarget&& EnableEyeTracking && !IsMini)
|
||||
if (TrackTarget && EnableEyeTracking && !isAnimatorControl && !IsMini)
|
||||
{
|
||||
var targetPosotion = TrackTarget.transform.position - HeadBone.transform.up*EyeHeight;
|
||||
var deltaPos = HeadBone.transform.InverseTransformPoint(targetPosotion);
|
||||
|
||||
@@ -271,6 +271,9 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CurrentUMAContainer.LoadPhysics(); //Need to load physics before loading FacialMorph
|
||||
|
||||
//Load FacialMorph
|
||||
if (CurrentUMAContainer.Head)
|
||||
{
|
||||
@@ -294,7 +297,6 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
|
||||
CurrentUMAContainer.MergeModel();
|
||||
CurrentUMAContainer.LoadPhysics();
|
||||
LoadAsset(UmaViewerMain.Instance.AbMotions.FirstOrDefault(a => a.Name.EndsWith($"anm_eve_chr{id}_00_idle01_loop")));
|
||||
}
|
||||
|
||||
@@ -971,6 +973,11 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
CurrentUMAContainer.isAnimatorControl = true;
|
||||
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 0, 0);
|
||||
}
|
||||
else if (clip.name.Contains("ear"))
|
||||
{
|
||||
CurrentUMAContainer.FaceOverrideController["clip_2"] = clip;
|
||||
CurrentUMAContainer.UmaFaceAnimator.Play("motion_1", 1, 0);
|
||||
}
|
||||
else if (clip.name.Contains("cam"))
|
||||
{
|
||||
var overrideController = Instantiate(CameraOverrideController);
|
||||
@@ -988,12 +995,17 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
{
|
||||
var facialMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name + "_face"));
|
||||
var cameraMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name + "_cam"));
|
||||
|
||||
var earMotion = Main.AbMotions.FirstOrDefault(a => a.Name.EndsWith(clip.name + "_ear"));
|
||||
if (facialMotion != null)
|
||||
{
|
||||
RecursiveLoadAsset(facialMotion);
|
||||
}
|
||||
|
||||
if (earMotion != null)
|
||||
{
|
||||
RecursiveLoadAsset(earMotion);
|
||||
}
|
||||
|
||||
if (cameraMotion != null)
|
||||
{
|
||||
RecursiveLoadAsset(cameraMotion);
|
||||
|
||||
@@ -646,21 +646,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
{
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
foreach(CySpringDataContainer cySpring in Builder.CurrentUMAContainer.GetComponentsInChildren<CySpringDataContainer>())
|
||||
{
|
||||
cySpring.EnablePhysics(isOn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEarMorphEnable(bool isOn)
|
||||
{
|
||||
if (Builder.CurrentUMAContainer)
|
||||
{
|
||||
foreach (CySpringDataContainer cySpring in Builder.CurrentUMAContainer.GetComponentsInChildren<CySpringDataContainer>())
|
||||
{
|
||||
cySpring.EnableEarPhysics(!isOn);
|
||||
}
|
||||
Builder.CurrentUMAContainer.SetDynamicBoneEnable(isOn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +735,8 @@ public class UmaViewerUI : MonoBehaviour
|
||||
if (animator_face)
|
||||
{
|
||||
animator_face.speed = AnimationSpeedSlider.value;
|
||||
animator_face.Play(0, -1, 0);
|
||||
animator_face.Play(0, 0, 0);
|
||||
animator_face.Play(0, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,7 +761,8 @@ public class UmaViewerUI : MonoBehaviour
|
||||
if (animator_face)
|
||||
{
|
||||
animator_face.speed = 0;
|
||||
animator_face.Play(0, -1, val);
|
||||
animator_face.Play(0, 0, val);
|
||||
animator_face.Play(0, 1, val);
|
||||
}
|
||||
|
||||
AnimationProgressText.text = string.Format("{0} / {1}", ToFrameFormat(val * AnimeClip.length, AnimeClip.frameRate), ToFrameFormat(AnimeClip.length, AnimeClip.frameRate));
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace Gallop
|
||||
else
|
||||
{
|
||||
dynamic.m_Damping = 0.2f;
|
||||
dynamic.m_Stiffness = Mathf.Clamp01(40 / spring._stiffnessForce);
|
||||
dynamic.m_Elasticity = Mathf.Clamp01(40 / spring._dragForce);
|
||||
dynamic.m_Stiffness = Mathf.Clamp01(45 / spring._stiffnessForce);
|
||||
dynamic.m_Elasticity = Mathf.Clamp01(45 / spring._dragForce);
|
||||
|
||||
}
|
||||
dynamic.m_Radius = spring._collisionRadius;
|
||||
@@ -125,7 +125,6 @@ namespace Gallop
|
||||
var tempParticle = dynamic.Particles.Find(a => { return a.m_Transform.gameObject.name == Childcollision._boneName; });
|
||||
if (tempParticle != null)
|
||||
{
|
||||
tempParticle.m_Damping = 0.2f;
|
||||
if (isTail)
|
||||
{
|
||||
tempParticle.m_Damping = 0.1f;
|
||||
@@ -135,8 +134,8 @@ namespace Gallop
|
||||
else
|
||||
{
|
||||
tempParticle.m_Damping = 0.2f;
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(40 / spring._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(40 / spring._dragForce);
|
||||
tempParticle.m_Stiffness = Mathf.Clamp01(45 / spring._stiffnessForce);
|
||||
tempParticle.m_Elasticity = Mathf.Clamp01(45 / spring._dragForce);
|
||||
}
|
||||
tempParticle.m_Radius = Childcollision._collisionRadius;
|
||||
foreach (string collisionName in Childcollision._collisionNameList)
|
||||
@@ -158,21 +157,7 @@ namespace Gallop
|
||||
{
|
||||
foreach(DynamicBone dynamic in DynamicBones)
|
||||
{
|
||||
if (!dynamic.m_Root.name.Contains("Ear"))
|
||||
{
|
||||
dynamic.enabled = isOn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableEarPhysics(bool isOn)
|
||||
{
|
||||
foreach (DynamicBone dynamic in DynamicBones)
|
||||
{
|
||||
if (dynamic.m_Root.name.Contains("Ear"))
|
||||
{
|
||||
dynamic.enabled = isOn;
|
||||
}
|
||||
dynamic.enabled = isOn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Unity;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static DynamicBone;
|
||||
|
||||
[System.Serializable]
|
||||
public class AssetTable
|
||||
@@ -40,6 +41,14 @@ public class TrsArray
|
||||
public Vector3 _scale;
|
||||
public Vector3 _rotation;
|
||||
public bool IsOverrideTarget;
|
||||
|
||||
public bool isPhysics;
|
||||
public Particle physicsParticle;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
Reference in New Issue
Block a user