Skip to content

Commit 74f1fdd

Browse files
authored
Merge pull request #2 from pikepikeid/Fix2
Fix2
2 parents bf67115 + 24a1570 commit 74f1fdd

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

VRCFTPicoModule/Assets/Locales/en-US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
"expression-tracking": "Expression Tracking",
1414
"init-failed": "Initialization failed, exception: {0}",
1515
"update-timeout": "Receive data timed out",
16-
"update-failed": "Update failed with exception: {0}"
16+
"update-failed": "Update failed with exception: {0}",
17+
"eye-gain-loaded": "Eye gain loaded: X={0}, Y={1}",
18+
"eye-gain-invalid": "Invalid eye_gain.txt format: \"{0}\"",
19+
"eye-gain-not-found": "eye_gain.txt not found, using default values",
20+
"eye-gain-disabled": "Eye gain disabled",
21+
"eye-gain-failed": "Failed to read eye_gain.txt"
1722
}

VRCFTPicoModule/Utils/Updater.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public Updater(UdpClient udpClient, ILogger logger, bool isLegacy, (bool, bool)
3131
private const float SmoothingFactor = 0.5f;
3232
private ModuleState _moduleState;
3333

34+
public float EyeGainX { get; internal set; } = 1.0f;
35+
public float EyeGainY { get; internal set; } = 1.0f;
36+
3437
public void Update(ModuleState state)
3538
{
3639
if (_udpClient == null)
@@ -81,20 +84,20 @@ private static float[] ParseData(byte[] data, bool isLegacy)
8184
return header.trackingType == 2 ? DataPacketHelpers.ByteArrayToStructure<DataPacket.DataPackBody>(data, Marshal.SizeOf<DataPacket.DataPackHeader>()).blendShapeWeight : [];
8285
}
8386

84-
private static void UpdateEye(float[] pShape)
87+
private void UpdateEye(float[] pShape)
8588
{
8689
var eye = UnifiedTracking.Data.Eye;
8790

8891
#region LeftEye
8992
eye.Left.Openness = 1f - pShape[(int)BlendShape.Index.EyeBlink_L];
90-
eye.Left.Gaze.x = pShape[(int)BlendShape.Index.EyeLookIn_L] - pShape[(int)BlendShape.Index.EyeLookOut_L];
91-
eye.Left.Gaze.y = pShape[(int)BlendShape.Index.EyeLookUp_L] - pShape[(int)BlendShape.Index.EyeLookDown_L];
93+
eye.Left.Gaze.x = (pShape[(int)BlendShape.Index.EyeLookIn_L] - pShape[(int)BlendShape.Index.EyeLookOut_L]) * EyeGainX;
94+
eye.Left.Gaze.y = (pShape[(int)BlendShape.Index.EyeLookUp_L] - pShape[(int)BlendShape.Index.EyeLookDown_L]) * EyeGainY;
9295
#endregion
9396

9497
#region RightEye
9598
eye.Right.Openness = 1f - pShape[(int)BlendShape.Index.EyeBlink_R];
96-
eye.Right.Gaze.x = pShape[(int)BlendShape.Index.EyeLookOut_R] - pShape[(int)BlendShape.Index.EyeLookIn_R];
97-
eye.Right.Gaze.y = pShape[(int)BlendShape.Index.EyeLookUp_R] - pShape[(int)BlendShape.Index.EyeLookDown_R];
99+
eye.Right.Gaze.x = (pShape[(int)BlendShape.Index.EyeLookOut_R] - pShape[(int)BlendShape.Index.EyeLookIn_R]) * EyeGainX;
100+
eye.Right.Gaze.y = (pShape[(int)BlendShape.Index.EyeLookUp_R] - pShape[(int)BlendShape.Index.EyeLookDown_R]) * EyeGainY;
98101
#endregion
99102

100103
#region Brow
@@ -111,8 +114,8 @@ private static void UpdateEye(float[] pShape)
111114
#region Eye
112115
SetParam(pShape, BlendShape.Index.EyeSquint_L, UnifiedExpressions.EyeSquintLeft);
113116
SetParam(pShape, BlendShape.Index.EyeSquint_R, UnifiedExpressions.EyeSquintRight);
114-
SetParam(pShape[(int)BlendShape.Index.EyeWide_L] / 0.5f, UnifiedExpressions.EyeWideLeft); // 目を見開けるように補正
115-
SetParam(pShape[(int)BlendShape.Index.EyeWide_R] / 0.5f, UnifiedExpressions.EyeWideRight); // 目を見開けるように補正
117+
SetParam(pShape, BlendShape.Index.EyeWide_L, UnifiedExpressions.EyeWideLeft);
118+
SetParam(pShape, BlendShape.Index.EyeWide_R, UnifiedExpressions.EyeWideRight);
116119
#endregion
117120
}
118121

VRCFTPicoModule/VRCFTPicoModule.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public class VRCFTPicoModule : ExtTrackingModule
1616
private static int _port;
1717
private Updater? _updater;
1818
private (bool, bool) _trackingAvailable;
19+
private static readonly string GainFilePath =
20+
Path.Combine(
21+
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!,
22+
"eye_gain.txt"
23+
);
24+
private static float _eyeGainX = 1.0f;
25+
private static float _eyeGainY = 1.0f;
1926

2027
public override (bool SupportsEye, bool SupportsExpression) Supported => (true, true);
2128

@@ -36,6 +43,7 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
3643
return initializationResult;
3744
}
3845

46+
3947
private async Task<(bool eyeSuccess, bool expressionSuccess)> InitializeAsync()
4048
{
4149
Logger.LogDebug(T("initializing-udp-clients"), string.Join(", ", Ports));
@@ -51,12 +59,15 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
5159
Logger.LogInformation(T("eye-tracking-disabled"));
5260
if (!_trackingAvailable.Item2)
5361
Logger.LogInformation(T("expression-tracking-disabled"));
54-
62+
63+
LoadEyeGain();
5564
_updater = new Updater(_udpClient, Logger, _port == Ports[1], _trackingAvailable);
65+
_updater.EyeGainX = _eyeGainX;
66+
_updater.EyeGainY = _eyeGainY;
5667

5768
return _trackingAvailable;
5869
}
59-
70+
6071
private (bool, bool) ReadConfiguration()
6172
{
6273
var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
@@ -140,4 +151,36 @@ public override void Teardown()
140151
_udpClient.Dispose();
141152
_updater = null;
142153
}
154+
private void LoadEyeGain()
155+
{
156+
try
157+
{
158+
if (!File.Exists(GainFilePath))
159+
{
160+
Logger.LogDebug("eye_gain.txt not found, using default values");
161+
return;
162+
}
163+
164+
var text = File.ReadAllText(GainFilePath).Trim();
165+
var parts = text.Split(',');
166+
167+
if (parts.Length >= 2 &&
168+
float.TryParse(parts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var x) &&
169+
float.TryParse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var y))
170+
{
171+
_eyeGainX = x;
172+
_eyeGainY = y;
173+
174+
Logger.LogInformation($"Eye gain loaded: X={_eyeGainX}, Y={_eyeGainY}");
175+
}
176+
else
177+
{
178+
Logger.LogWarning($"Invalid eye_gain.txt format: \"{text}\"");
179+
}
180+
}
181+
catch (Exception ex)
182+
{
183+
Logger.LogError(ex, "Failed to read eye_gain.txt");
184+
}
185+
}
143186
}

0 commit comments

Comments
 (0)