Skip to content

Commit

Permalink
Merge pull request #3 from jensnt/master
Browse files Browse the repository at this point in the history
Adding new Option UntrackedEyeFollowTracked
  • Loading branch information
Chickenbreadlp authored Jul 27, 2024
2 parents 4d3c0f5 + e5413d6 commit 02735c7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
11 changes: 11 additions & 0 deletions ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,6 +51,7 @@ public void InitConfig()
readDelay = 10;
pickyTracking = false;
stabalizingCycles = 0;
untrackedEyeFollowTracked = false;
opennessStrategy = OpennessStrategy.RestrictedSpeed;
squeezeThreshold = 0.15f;
widenThreshold = 0.9f;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
56 changes: 44 additions & 12 deletions VarjoTrackingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
Expand Down Expand Up @@ -106,29 +109,58 @@ private static (float openness, float squeeze, float widen) ParseOpenness(float
/// <param name="externalMeasurements">Auxillary Varjo measurements object</param>
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;
}
}
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;
}
}


// Parse openness as boolean or float depending on config
switch (Config.opennessStrategy)
{
Expand Down Expand Up @@ -253,4 +285,4 @@ public override void Teardown()
tracker.Teardown();
}
}
}
}

0 comments on commit 02735c7

Please sign in to comment.