Skip to content

Commit

Permalink
Added fix for Eye Lids shooting open
Browse files Browse the repository at this point in the history
Added a Fixe for the Eye Lids shooting open after prolonged closure of the eyes.

Also implemented Conditional Builds to generate seperate builds for 3rd Gen Varjo HMDs (as the camera resolution differs between those and older Varjo HMDs)
  • Loading branch information
Chickenbreadlp committed Jan 21, 2023
1 parent 96dc85f commit 17d3c8f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 18 deletions.
31 changes: 31 additions & 0 deletions VRCFTVarjoModule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>VRCFTVarjoModule</RootNamespace>
Expand Down Expand Up @@ -69,6 +70,36 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %283rd Gen HMD%29|AnyCPU'">
<OutputPath>bin\Release %283rd Gen HMD%29\</OutputPath>
<DefineConstants>TRACE;GEN3HMD</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %283rd Gen HMD%29|x64'">
<OutputPath>bin\x64\Release %283rd Gen HMD%29\</OutputPath>
<DefineConstants>TRACE;GEN3HMD</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %283rd Gen HMD%29|x86'">
<OutputPath>bin\x86\Release %283rd Gen HMD%29\</OutputPath>
<DefineConstants>TRACE;GEN3HMD</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
Expand Down
13 changes: 11 additions & 2 deletions VRCFTVarjoModule.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1738
# Visual Studio Version 16
VisualStudioVersion = 16.0.32901.82
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VRCFTVarjoModule", "VRCFTVarjoModule.csproj", "{381EDD16-E4AF-4971-B70B-77E3F17A8204}"
EndProject
Expand All @@ -10,6 +10,9 @@ Global
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release (3rd Gen HMD)|Any CPU = Release (3rd Gen HMD)|Any CPU
Release (3rd Gen HMD)|x64 = Release (3rd Gen HMD)|x64
Release (3rd Gen HMD)|x86 = Release (3rd Gen HMD)|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
Expand All @@ -21,6 +24,12 @@ Global
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Debug|x64.Build.0 = Debug|x64
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Debug|x86.ActiveCfg = Debug|x86
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Debug|x86.Build.0 = Debug|x86
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|Any CPU.ActiveCfg = Release (3rd Gen HMD)|Any CPU
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|Any CPU.Build.0 = Release (3rd Gen HMD)|Any CPU
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|x64.ActiveCfg = Release (3rd Gen HMD)|x64
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|x64.Build.0 = Release (3rd Gen HMD)|x64
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|x86.ActiveCfg = Release (3rd Gen HMD)|x86
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release (3rd Gen HMD)|x86.Build.0 = Release (3rd Gen HMD)|x86
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release|Any CPU.ActiveCfg = Release|Any CPU
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release|Any CPU.Build.0 = Release|Any CPU
{381EDD16-E4AF-4971-B70B-77E3F17A8204}.Release|x64.ActiveCfg = Release|x64
Expand Down
69 changes: 53 additions & 16 deletions VarjoTrackingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ namespace VRCFTVarjoModule
// This class contains the overrides for any VRCFT Tracking Data struct functions
public static class TrackingData
{
enum VarjoOpennessMode : byte
{
Squeeze = 0,
Openness = 1,
Widen = 2
}

// Magic numbers to disect the 0-1 Varjo Openness float into SRanipal Openness, Widen & Squeeze values
// Based on Testing from @Chickenbread; may need adjusting
private static readonly float EYE_SQUEEZE_THRESHOLD = 0.15f, EYE_WIDEN_THRESHOLD = 0.90f;
// Threshold of the maximum opening in Eye Openness that will be tracked as long as the eye status is "invalid"
private static readonly float MAX_OPENNESS_DEVIATION = 0.1f;

// 999 for min and -1 for max, to ensure these Values get overwritten the first runthrough
private static double _minPupilSize = 999, _maxPupilSize = -1;
Expand All @@ -28,7 +37,7 @@ public static void Update(ref Eye data, GazeRay external, float openness, GazeEy
data.Look = new Vector2((float)external.forward.x, (float)external.forward.y);
}

parseOpenness(ref data, openness);
parseOpenness(ref data, openness, eyeStatus >= GazeEyeStatus.Compensated);
}

public static void Update(ref Eye data, GazeRay external, float openness, GazeStatus combinedStatus)
Expand All @@ -38,7 +47,7 @@ public static void Update(ref Eye data, GazeRay external, float openness, GazeSt
data.Look = new Vector2((float)external.forward.x, (float)external.forward.y);
}

parseOpenness(ref data, openness);
parseOpenness(ref data, openness, combinedStatus != GazeStatus.Invalid);
}

// This function parses the external module's full-data data into multiple VRCFT-Parseable single-eye structs
Expand Down Expand Up @@ -101,25 +110,47 @@ private static double calculateEyeDilation(ref double pupilSize)

// This function is used to disect the single Varjo Openness Float into the SRanipal Openness, Widen & Squeeze values
// As the three SRanipal Parameters are exclusive to one another (if one is between 0 or 1, the others have to be either 0 or 1), we only need to do maths for one parameter
private static void parseOpenness(ref Eye data, float openness)
private static void parseOpenness(ref Eye data, float openness, bool trackingValid)
{
float srOpenness;
VarjoOpennessMode mode;


if (openness <= EYE_SQUEEZE_THRESHOLD)
{
data.Squeeze = (openness / -EYE_SQUEEZE_THRESHOLD) + 1;
data.Openness = 0;
data.Widen = 0;
srOpenness = 0;
mode = VarjoOpennessMode.Squeeze;
}
else if (openness >= EYE_WIDEN_THRESHOLD)
{
data.Squeeze = 0;
data.Openness = 1;
data.Widen = (openness - EYE_WIDEN_THRESHOLD) / (1 - EYE_WIDEN_THRESHOLD);
srOpenness = 1;
mode = VarjoOpennessMode.Widen;
}
else
{
data.Squeeze = 0;
data.Openness = (openness - EYE_SQUEEZE_THRESHOLD) / (EYE_WIDEN_THRESHOLD - EYE_SQUEEZE_THRESHOLD);
data.Widen = 0;
srOpenness = (openness - EYE_SQUEEZE_THRESHOLD) / (EYE_WIDEN_THRESHOLD - EYE_SQUEEZE_THRESHOLD);
mode = VarjoOpennessMode.Openness;
}

if (trackingValid || srOpenness < data.Openness + MAX_OPENNESS_DEVIATION)
{
data.Openness = srOpenness;

switch(mode)
{
case VarjoOpennessMode.Squeeze:
data.Squeeze = (openness / -EYE_SQUEEZE_THRESHOLD) + 1;
data.Widen = 0;
break;
case VarjoOpennessMode.Widen:
data.Squeeze = 0;
data.Widen = (openness - EYE_WIDEN_THRESHOLD) / (1 - EYE_WIDEN_THRESHOLD);
break;
default:
data.Squeeze = 0;
data.Widen = 0;
break;
}
}
}

Expand All @@ -135,7 +166,13 @@ public class VarjoTrackingModule : ExtTrackingModule
private MemoryMappedFile MemMapFile;
private MemoryMappedViewAccessor ViewAccessor;
private IntPtr EyeImagePointer;

// Values for the Camera buffer size in VRCFT
#if GEN3HMD
private static readonly int CAMERA_WIDTH = 1280, CAMERA_HEIGHT = 400; // 3rd Gen Varjo HMDs (VR-3, XR-3, Aero)
#else
private static readonly int CAMERA_WIDTH = 2560, CAMERA_HEIGHT = 800; // 1st & 2nd Gen Varjo HMDs (VR-1, VR-2, XR-1)
#endif


public override (bool SupportsEye, bool SupportsLip) Supported => (true, false);

Expand Down Expand Up @@ -164,7 +201,7 @@ public override (bool eyeSuccess, bool lipSuccess) Initialize(bool eye, bool lip
ViewAccessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
EyeImagePointer = new IntPtr(ptr);
UnifiedTrackingData.LatestEyeData.SupportsImage = true;
UnifiedTrackingData.LatestEyeData.ImageSize = (2560, 800);
UnifiedTrackingData.LatestEyeData.ImageSize = (CAMERA_WIDTH, CAMERA_HEIGHT);
}
catch (FileNotFoundException)
{
Expand Down Expand Up @@ -203,9 +240,9 @@ private unsafe void UpdateEyeImage()
}
if (UnifiedTrackingData.LatestEyeData.ImageData == null)
{
UnifiedTrackingData.LatestEyeData.ImageData = new byte[2560 * 800];
UnifiedTrackingData.LatestEyeData.ImageData = new byte[CAMERA_WIDTH * CAMERA_HEIGHT];
}
Marshal.Copy(EyeImagePointer, UnifiedTrackingData.LatestEyeData.ImageData, 0, 2560*800);
Marshal.Copy(EyeImagePointer, UnifiedTrackingData.LatestEyeData.ImageData, 0, CAMERA_WIDTH * CAMERA_HEIGHT);
}

// The update function needs to be defined separately in case the user is running with the --vrcft-nothread launch parameter
Expand Down

0 comments on commit 17d3c8f

Please sign in to comment.