From 685c7c76b49d666669715bc5fd508eccacce0968 Mon Sep 17 00:00:00 2001 From: jensnt <14246748+jensnt@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:28:09 +0000 Subject: [PATCH 1/3] Adding new Option UntrackedEyeFollowTracked --- ConfigManager.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ConfigManager.cs b/ConfigManager.cs index eb77f22..0edad95 100644 --- a/ConfigManager.cs +++ b/ConfigManager.cs @@ -17,6 +17,7 @@ internal class ConfigManager public int readDelay { get; protected set; } public bool pickyTracking { get; protected set; } public uint stabalizingCycles { get; protected set; } + public bool untrackedEyeFollowTracked { get; protected set; } public OpennessStrategy opennessStrategy { get; protected set; } // Magic numbers for float lid parsing @@ -50,6 +51,7 @@ public void InitConfig() readDelay = 10; pickyTracking = false; stabalizingCycles = 0; + untrackedEyeFollowTracked = false; opennessStrategy = OpennessStrategy.RestrictedSpeed; squeezeThreshold = 0.15f; widenThreshold = 0.9f; @@ -92,6 +94,12 @@ public void WriteConfig() fs.WriteLine("; This can visually freeze your gaze when set too high or with unstable tracking, so use with caution! (also affects Eye Lid Strat: RestrictedSpeed)"); fs.WriteLine($"StabalizingCycles={stabalizingCycles}"); + fs.WriteLine(""); + fs.WriteLine("; If one eye temporary lost tracking while the other is still tracked, this option will make the untracked eye try to follow the tracked one during that time."); + fs.WriteLine("; This option can be especially useful in combination with PickyTracking."); + fs.WriteLine("; (this setting applies to Gaze ONLY and has no effect on the Lid strats)"); + fs.WriteLine($"UntrackedEyeFollowTracked={untrackedEyeFollowTracked}"); + fs.WriteLine(""); fs.WriteLine("; EyeLidStrat defines how the module calculates the Openness Value"); fs.WriteLine("; There are 5 possible options: Bool, Stepped, RestrictedSpeed, RawFloat & Hybrid"); @@ -222,6 +230,9 @@ public void Reload() { else Logger.LogWarning($"{value} not a valid value for StabalizingCycles"); break; } + case "untrackedeyefollowtracked": + untrackedEyeFollowTracked = ParseStringToBool(value); + break; case "eyelidstrat": { var strat = StringToOpennessStrat(value); From e1515cf94e4e34ac436be42089fbfb32d20da49a Mon Sep 17 00:00:00 2001 From: jensnt <14246748+jensnt@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:31:08 +0000 Subject: [PATCH 2/3] Adding new Option UntrackedEyeFollowTracked --- VarjoTrackingModule.cs | 58 +++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/VarjoTrackingModule.cs b/VarjoTrackingModule.cs index c2dbf26..caa6189 100644 --- a/VarjoTrackingModule.cs +++ b/VarjoTrackingModule.cs @@ -16,6 +16,9 @@ public static class TrackingData { internal static ConfigManager Config { get; set; } internal static uint leftTimeoutCycles = 0, rightTimeoutCycles = 0; + internal static bool isTrackingLeft = false, isTrackingRight = false; + internal static Vector2 refGazeLeft = new Vector2(0, 0), refGazeRight = new Vector2(0, 0); + internal static Vector2 gazeLeft = new Vector2(0, 0), gazeRight = new Vector2(0, 0); internal static GazeEyeStatus validGazeStatus { get; set; } /// @@ -106,29 +109,60 @@ private static (float openness, float squeeze, float widen) ParseOpenness(float /// Auxillary Varjo measurements object public static void Update(ref UnifiedEyeData data, ref UnifiedExpressionShape[] expressionData, GazeData external, EyeMeasurements externalMeasurements) { - // Set the Gaze and Pupil Size for each eye when their status is somewhat reliable according to the SDK + // Detect which eye is tracked depending on if their status is somewhat reliable according to the SDK + isTrackingRight = false; if (external.rightStatus >= validGazeStatus) { - if (rightTimeoutCycles == 0) - { - data.Right.Gaze = GetGazeVector(external.rightEye); - data.Right.PupilDiameter_MM = externalMeasurements.rightPupilDiameterInMM; - } + if (rightTimeoutCycles == 0) isTrackingRight = true; else rightTimeoutCycles--; } else rightTimeoutCycles = Config.stabalizingCycles; + isTrackingLeft = false; if (external.leftStatus >= validGazeStatus) { - if (leftTimeoutCycles == 0) - { - data.Left.Gaze = GetGazeVector(external.leftEye); - data.Left.PupilDiameter_MM = externalMeasurements.leftPupilDiameterInMM; - } + if (leftTimeoutCycles == 0) isTrackingLeft = true; else leftTimeoutCycles--; } else leftTimeoutCycles = Config.stabalizingCycles; + + // Set the Gaze and Pupil Size for each eye + if (isTrackingRight && isTrackingLeft) + { + gazeRight = GetGazeVector(external.rightEye); + gazeLeft = GetGazeVector(external.leftEye); + refGazeRight = gazeRight; + refGazeLeft = gazeLeft; + data.Right.Gaze = gazeRight; + data.Right.PupilDiameter_MM = externalMeasurements.rightPupilDiameterInMM; + data.Left.Gaze = gazeLeft; + data.Left.PupilDiameter_MM = externalMeasurements.leftPupilDiameterInMM; + } + else if (isTrackingRight) + { + gazeRight = GetGazeVector(external.rightEye); + data.Right.Gaze = gazeRight; + data.Right.PupilDiameter_MM = externalMeasurements.rightPupilDiameterInMM; + if (Config.untrackedEyeFollowTracked) + { + data.Left.Gaze = (gazeRight - refGazeRight) + refGazeLeft; + data.Left.PupilDiameter_MM = externalMeasurements.rightPupilDiameterInMM; + } + } + else if (isTrackingLeft) + { + gazeLeft = GetGazeVector(external.leftEye); + data.Left.Gaze = gazeLeft; + data.Left.PupilDiameter_MM = externalMeasurements.leftPupilDiameterInMM; + if (Config.untrackedEyeFollowTracked) + { + data.Right.Gaze = (gazeLeft - refGazeLeft) + refGazeRight; + data.Right.PupilDiameter_MM = externalMeasurements.leftPupilDiameterInMM; + } + } + + // Parse openness as boolean or float depending on config switch (Config.opennessStrategy) { @@ -253,4 +287,4 @@ public override void Teardown() tracker.Teardown(); } } -} \ No newline at end of file +} From e5413d6475978d9071fa1ff8c29a2e6454a90a31 Mon Sep 17 00:00:00 2001 From: jensnt <14246748+jensnt@users.noreply.github.com> Date: Sat, 27 Jul 2024 16:14:26 +0000 Subject: [PATCH 3/3] Do not set pupil size from other eye Do not set pupil size from other eye. See discussion in: https://github.com/Chickenbreadlp/VRCFTVarjoModule/pull/3 --- VarjoTrackingModule.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/VarjoTrackingModule.cs b/VarjoTrackingModule.cs index caa6189..6e288b7 100644 --- a/VarjoTrackingModule.cs +++ b/VarjoTrackingModule.cs @@ -147,7 +147,6 @@ public static void Update(ref UnifiedEyeData data, ref UnifiedExpressionShape[] if (Config.untrackedEyeFollowTracked) { data.Left.Gaze = (gazeRight - refGazeRight) + refGazeLeft; - data.Left.PupilDiameter_MM = externalMeasurements.rightPupilDiameterInMM; } } else if (isTrackingLeft) @@ -158,7 +157,6 @@ public static void Update(ref UnifiedEyeData data, ref UnifiedExpressionShape[] if (Config.untrackedEyeFollowTracked) { data.Right.Gaze = (gazeLeft - refGazeLeft) + refGazeRight; - data.Right.PupilDiameter_MM = externalMeasurements.leftPupilDiameterInMM; } }