-
Notifications
You must be signed in to change notification settings - Fork 2
/
EyeData.cs
114 lines (91 loc) · 2.71 KB
/
EyeData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Text.Json;
using System.Text.Json.Serialization;
namespace PimaxCrystalAdvanced;
public struct EyeData
{
[JsonConverter(typeof(Vector2MethodConverter))]
public struct Vector2
{
public Vector2(float x, float y)
{
X = x;
Y = y;
}
public float X;
public float Y;
public VRCFaceTracking.Core.Types.Vector2 ToVRCFT()
{
return new VRCFaceTracking.Core.Types.Vector2(X, Y);
}
}
public struct Eye
{
[JsonInclude]
[JsonPropertyName("gaze_direction_is_valid")]
public bool GazeDirectionIsValid;
[JsonInclude]
[JsonPropertyName("gaze_direction")]
public Vector2 GazeDirection;
[JsonInclude]
[JsonPropertyName("pupil_diameter_is_valid")]
public bool PupilDiameterIsValid;
[JsonInclude]
[JsonPropertyName("pupil_diameter_mm")]
public float PupilDiameterMm;
[JsonInclude]
[JsonPropertyName("openness_is_valid")]
public bool OpennessIsValid;
[JsonInclude]
[JsonPropertyName("openness")]
public float Openness;
[JsonInclude]
[JsonPropertyName("wide")]
public float Wide;
[JsonInclude]
[JsonPropertyName("squeeze")]
public float Squeeze;
[JsonInclude]
[JsonPropertyName("frown")]
public float Frown;
}
[JsonInclude]
[JsonPropertyName("left")]
public Eye Left;
[JsonInclude]
[JsonPropertyName("right")]
public Eye Right;
public EyeData(Eye left, Eye right)
{
Left = left;
Right = right;
}
}
public class Vector2MethodConverter : JsonConverter<EyeData.Vector2>
{
public override EyeData.Vector2 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
{
return new EyeData.Vector2();
}
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException($"Unexpected token {reader.TokenType}");
}
var array = JsonSerializer.Deserialize<float[]>(ref reader, options);
if (array == null || array.Length < 2)
{
throw new JsonException($"Expected array of length 2, got {array?.Length}");
}
var x = array[0];
var y = array[1];
return new EyeData.Vector2(x, y);
}
public override void Write(Utf8JsonWriter writer, EyeData.Vector2 value, JsonSerializerOptions options)
{
writer.WriteStartArray();
writer.WriteNumberValue(value.X);
writer.WriteNumberValue(value.Y);
writer.WriteEndArray();
}
}