Face tracking components override

This commit is contained in:
SDraw 2022-09-23 23:27:38 +03:00
parent 65f8992a73
commit b6a4e0cd0a
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
8 changed files with 99 additions and 10 deletions

View file

@ -1,4 +1,5 @@
using ABI_RC.Core.Player;
using ABI.CCK.Components;
using ABI_RC.Core.Player;
using UnityEngine;
namespace ml_dht
@ -8,7 +9,9 @@ namespace ml_dht
bool m_enabled = true;
float m_smoothing = 0.5f;
bool m_mirrored = false;
bool m_faceOverride = true;
CVRAvatar m_avatarDescriptior = null;
RootMotion.FinalIK.LookAtIK m_lookIK = null;
Transform m_camera = null;
Transform m_headBone = null;
@ -61,8 +64,38 @@ namespace ml_dht
}
}
public void OnFaceTrackingUpdate(CVRFaceTracking p_component)
{
if(m_enabled && m_faceOverride)
{
if(m_avatarDescriptior != null)
m_avatarDescriptior.useVisemeLipsync = false;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Jaw_Open] = m_mouthShapes.x * 100f;
if(m_mouthShapes.y < 0f)
{
float l_weight = Mathf.Clamp(Mathf.InverseLerp(0.25f, 1f, -m_mouthShapes.y), 0f, 1f) * 100f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Pout] = 0f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Left] = l_weight;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Right] = l_weight;
}
if(m_mouthShapes.y > 0f)
{
float l_weight = Mathf.Clamp(Mathf.InverseLerp(0.25f, 1f, m_mouthShapes.y), 0f, 1f) * 100f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Pout] = l_weight;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Left] = 0f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Right] = 0f;
}
p_component.LipSyncWasUpdated = true;
p_component.UpdateLipShapes();
}
}
public void OnSetupAvatarGeneral()
{
m_avatarDescriptior = PlayerSetup.Instance._avatar.GetComponent<CVRAvatar>();
m_headBone = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Head);
m_lookIK = PlayerSetup.Instance._avatar.GetComponent<RootMotion.FinalIK.LookAtIK>();
@ -71,9 +104,11 @@ namespace ml_dht
if(m_lookIK != null)
m_lookIK.solver.OnPostUpdate += this.OnLookIKPostUpdate;
}
public void OnAvatarClear()
{
m_avatarDescriptior = null;
m_lookIK = null;
m_headBone = null;
m_lastHeadRotation = Quaternion.identity;
@ -97,5 +132,9 @@ namespace ml_dht
{
m_mirrored = p_state;
}
public void SetFaceOverride(bool p_state)
{
m_faceOverride = p_state;
}
}
}