Better tracking for all avatars

This commit is contained in:
SDraw 2022-10-04 19:58:10 +00:00 committed by SDraw
parent 3b998827f5
commit 71c0068652
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
6 changed files with 36 additions and 33 deletions

View file

@ -5,7 +5,7 @@ Merged set of MelonLoader mods for ChilloutVR.
|-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------| |-----------|------------|----------------|-----------------------------------------------------------------|----------------|-------|
| Avatar Change Info | ml_aci | 1.0.2 | Yes | Working | | Avatar Change Info | ml_aci | 1.0.2 | Yes | Working |
| Avatar Motion Tweaker | ml_amt | 1.1.1 | On review | Working | | Avatar Motion Tweaker | ml_amt | 1.1.1 | On review | Working |
| Desktop Head Tracking | ml_dht | 1.0.3 | On review | Working | | Desktop Head Tracking | ml_dht | 1.0.4 | On review | Working |
| Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working | | Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working |
| Four Point Tracking | ml_fpt | 1.0.7 | On review | Working | | Four Point Tracking | ml_fpt | 1.0.7 | On review | Working |
| Leap Motion Extension | ml_lme | 1.2.0 | On review | Working | | Leap Motion Extension | ml_lme | 1.2.0 | On review | Working |

View file

@ -4,14 +4,15 @@ using UnityEngine;
namespace ml_dht namespace ml_dht
{ {
class FaceTracked : MonoBehaviour [DisallowMultipleComponent]
class HeadTracked : MonoBehaviour
{ {
bool m_enabled = false; bool m_enabled = false;
float m_smoothing = 0.5f; float m_smoothing = 0.5f;
bool m_mirrored = false; bool m_mirrored = false;
bool m_faceOverride = true; bool m_faceOverride = true;
CVRAvatar m_avatarDescriptior = null; CVRAvatar m_avatarDescriptor = null;
RootMotion.FinalIK.LookAtIK m_lookIK = null; RootMotion.FinalIK.LookAtIK m_lookIK = null;
Transform m_camera = null; Transform m_camera = null;
Transform m_headBone = null; Transform m_headBone = null;
@ -45,8 +46,8 @@ namespace ml_dht
{ {
if(m_enabled && (m_headBone != null)) if(m_enabled && (m_headBone != null))
{ {
m_lastHeadRotation = Quaternion.Slerp(m_lastHeadRotation, m_headRotation * m_bindRotation, m_smoothing); m_lastHeadRotation = Quaternion.Slerp(m_lastHeadRotation, m_avatarDescriptor.transform.rotation * (m_headRotation * m_bindRotation), m_smoothing);
m_headBone.localRotation = m_lastHeadRotation; m_headBone.rotation = m_lastHeadRotation;
} }
} }
@ -68,26 +69,15 @@ namespace ml_dht
{ {
if(m_enabled && m_faceOverride) if(m_enabled && m_faceOverride)
{ {
if(m_avatarDescriptior != null) if(m_avatarDescriptor != null)
m_avatarDescriptior.useVisemeLipsync = false; m_avatarDescriptor.useVisemeLipsync = false;
float l_weight = Mathf.Clamp(Mathf.InverseLerp(0.25f, 1f, Mathf.Abs(m_mouthShapes.y)), 0f, 1f) * 100f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Jaw_Open] = m_mouthShapes.x * 100f; p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Jaw_Open] = m_mouthShapes.x * 100f;
p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Pout] = ((m_mouthShapes.y > 0f) ? l_weight : 0f);
if(m_mouthShapes.y < 0f) p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Left] = ((m_mouthShapes.y < 0f) ? l_weight : 0f);
{ p_component.BlendShapeValues[(int)ViveSR.anipal.Lip.LipShape_v2.Mouth_Smile_Right] = ((m_mouthShapes.y < 0f) ? l_weight : 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.LipSyncWasUpdated = true;
p_component.UpdateLipShapes(); p_component.UpdateLipShapes();
} }
@ -95,12 +85,12 @@ namespace ml_dht
public void OnCalibrateAvatar() public void OnCalibrateAvatar()
{ {
m_avatarDescriptior = PlayerSetup.Instance._avatar.GetComponent<CVRAvatar>(); m_avatarDescriptor = PlayerSetup.Instance._avatar.GetComponent<CVRAvatar>();
m_headBone = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Head); m_headBone = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Head);
m_lookIK = PlayerSetup.Instance._avatar.GetComponent<RootMotion.FinalIK.LookAtIK>(); m_lookIK = PlayerSetup.Instance._avatar.GetComponent<RootMotion.FinalIK.LookAtIK>();
if(m_headBone != null) if(m_headBone != null)
m_bindRotation = m_headBone.localRotation; m_bindRotation = (m_avatarDescriptor.transform.GetMatrix().inverse * m_headBone.GetMatrix()).rotation;
if(m_lookIK != null) if(m_lookIK != null)
m_lookIK.solver.OnPostUpdate += this.OnLookIKPostUpdate; m_lookIK.solver.OnPostUpdate += this.OnLookIKPostUpdate;
@ -108,7 +98,7 @@ namespace ml_dht
} }
public void OnAvatarClear() public void OnAvatarClear()
{ {
m_avatarDescriptior = null; m_avatarDescriptor = null;
m_lookIK = null; m_lookIK = null;
m_headBone = null; m_headBone = null;
m_lastHeadRotation = Quaternion.identity; m_lastHeadRotation = Quaternion.identity;
@ -121,7 +111,7 @@ namespace ml_dht
{ {
m_enabled = p_state; m_enabled = p_state;
if(m_enabled) if(m_enabled)
m_lastHeadRotation = m_bindRotation; m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation);
} }
} }
public void SetSmoothing(float p_value) public void SetSmoothing(float p_value)

View file

@ -11,7 +11,7 @@ namespace ml_dht
byte[] m_buffer = null; byte[] m_buffer = null;
TrackingData m_trackingData; TrackingData m_trackingData;
FaceTracked m_localTracked = null; HeadTracked m_localTracked = null;
public override void OnApplicationStart() public override void OnApplicationStart()
{ {
@ -59,7 +59,7 @@ namespace ml_dht
while(PlayerSetup.Instance == null) while(PlayerSetup.Instance == null)
yield return null; yield return null;
m_localTracked = PlayerSetup.Instance.gameObject.AddComponent<FaceTracked>(); m_localTracked = PlayerSetup.Instance.gameObject.AddComponent<HeadTracked>();
m_localTracked.SetEnabled(Settings.Enabled); m_localTracked.SetEnabled(Settings.Enabled);
m_localTracked.SetMirrored(Settings.Mirrored); m_localTracked.SetMirrored(Settings.Mirrored);
m_localTracked.SetSmoothing(Settings.Smoothing); m_localTracked.SetSmoothing(Settings.Smoothing);

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyTitle("DesktopHeadTracking")] [assembly: AssemblyTitle("DesktopHeadTracking")]
[assembly: AssemblyVersion("1.0.3")] [assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.3")] [assembly: AssemblyFileVersion("1.0.4")]
[assembly: MelonLoader.MelonInfo(typeof(ml_dht.DesktopHeadTracking), "DesktopHeadTracking", "1.0.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")] [assembly: MelonLoader.MelonInfo(typeof(ml_dht.DesktopHeadTracking), "DesktopHeadTracking", "1.0.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")] [assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]

12
ml_dht/Utils.cs Normal file
View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace ml_dht
{
static class Utils
{
public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
{
return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one);
}
}
}

View file

@ -73,13 +73,14 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FaceTracked.cs" /> <Compile Include="HeadTracked.cs" />
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="MemoryMapReader.cs" /> <Compile Include="MemoryMapReader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripts.cs" /> <Compile Include="Scripts.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />
<Compile Include="TrackingData.cs" /> <Compile Include="TrackingData.cs" />
<Compile Include="Utils.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<ItemGroup> <ItemGroup>