Skip to content

Commit a5d45fa

Browse files
authored
Merge pull request #1 from esnya/fix/reconnection
Fix Gaze Space & Reconnection Handling
2 parents 88afeff + 1302422 commit a5d45fa

4 files changed

Lines changed: 33 additions & 37 deletions

File tree

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ tab_width = 4
271271
indent_size = 4
272272
dotnet_style_operator_placement_when_wrapping = beginning_of_line
273273
end_of_line = crlf
274+
dotnet_diagnostic.CA1051.severity = none
274275

275276

276277
[{VS_PC_SDK,FaceData}.cs]

ViveStreamingEyes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void UpdateEyeDirection(Eye eye, FaceData.EyeDataIndex xIndex, FaceData.
8888
var direction = new float3(
8989
eyeData[xIndex],
9090
eyeData[yIndex],
91-
eyeData[zIndex]
91+
-eyeData[zIndex]
9292
).Normalized;
9393

9494
if (!direction.IsNaN && !direction.Approximately(float3.Zero, 0.001f))

ViveStreamingFaceTrackingDriver.cs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,9 @@ public sealed class ViveStreamingFaceTrackingDriver : IInputDriver, IDisposable
2121
private static string? eyeData;
2222
private static string? lipData;
2323

24-
private bool _active;
25-
public bool Active
26-
{
27-
set
28-
{
29-
if (_active == value)
30-
{
31-
return;
32-
}
24+
private bool _tracking;
25+
public bool active;
3326

34-
_active = value;
35-
if (value)
36-
{
37-
if (!VS_PC_SDK.VS_StartFaceTracking())
38-
{
39-
ResoniteMod.Error("Failed to start face tracking");
40-
throw new InvalidOperationException("Failed to start face tracking");
41-
}
42-
}
43-
else
44-
{
45-
if (!VS_PC_SDK.VS_StopFaceTracking())
46-
{
47-
throw new InvalidOperationException("Failed to stop face tracking");
48-
}
49-
}
50-
}
51-
get
52-
{
53-
return _active;
54-
}
55-
}
5627
public ViveStreamingFaceTrackingDriver()
5728
{
5829
ResoniteMod.Debug($"Initializing Vive Streaming Face Tracking");
@@ -169,13 +140,38 @@ private static void OnDebugLog(string message)
169140

170141
public void UpdateInputs(float deltaTime)
171142
{
143+
if (connected && !_tracking && active)
144+
{
145+
if (!VS_PC_SDK.VS_StartFaceTracking())
146+
{
147+
ResoniteMod.Error("Failed to start face tracking");
148+
throw new InvalidOperationException("Failed to start face tracking");
149+
}
150+
_tracking = true;
151+
}
152+
153+
if (connected && _tracking && !active)
154+
{
155+
if (!VS_PC_SDK.VS_StopFaceTracking())
156+
{
157+
ResoniteMod.Error("Failed to stop face tracking");
158+
throw new InvalidOperationException("Failed to stop face tracking");
159+
}
160+
_tracking = false;
161+
}
162+
163+
if (!connected)
164+
{
165+
_tracking = false;
166+
}
167+
172168
eyes?.UpdateInputs(connected, ref eyeData);
173169
mouth?.UpdateInputs(connected, ref lipData);
174170
}
175171

176172
public void Dispose()
177173
{
178-
Active = false;
174+
active = false;
179175

180176
var result = VS_PC_SDK.VS_Release();
181177
if (result != 0)

ViveStreamingFaceTrackingMod.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System;
22
using System.Linq;
33
using System.Reflection;
4-
54
using Elements.Core;
6-
using ResoniteModLoader;
75
using FrooxEngine;
6+
using ResoniteModLoader;
87

98

109

@@ -55,11 +54,11 @@ private static void Init(ResoniteMod modInstance)
5554
{
5655
config = modInstance?.GetConfiguration();
5756

58-
driver.Active = config?.GetValue(enabledkey) ?? true;
57+
driver.active = config?.GetValue(enabledkey) ?? true;
5958

6059
enabledkey.OnChanged += (_) =>
6160
{
62-
driver.Active = config?.GetValue(enabledkey) ?? true;
61+
driver.active = config?.GetValue(enabledkey) ?? true;
6362
};
6463
}
6564

0 commit comments

Comments
 (0)