Skip to content

Commit 96a4e8c

Browse files
committed
Decoupled expressions from module, now in config file
1 parent fc24fa3 commit 96a4e8c

7 files changed

+447
-97
lines changed

BabbleExpressions.cs

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,86 @@
1-
namespace VRCFaceTracking.Babble;
2-
public partial class BabbleOSC
1+
using Newtonsoft.Json;
2+
using System.Reflection;
3+
using VRCFaceTracking.Core.Params.Expressions;
4+
using VRCFaceTracking.Babble.Collections;
5+
6+
namespace VRCFaceTracking.Babble;
7+
public static class BabbleExpressions
38
{
4-
public Dictionary<string, float> BabbleExpressionMap = new()
9+
private const string BabbleExpressionsPath = "BabbleExpressions.json";
10+
11+
public static readonly TwoKeyDictionary<UnifiedExpressions, string, float> BabbleExpressionMap;
12+
static BabbleExpressions()
513
{
6-
{ "/cheekPuffLeft", 0f },
7-
{ "/cheekPuffRight", 0f },
8-
{ "/cheekSuckLeft", 0f },
9-
{ "/cheekSuckRight", 0f },
10-
{ "/jawOpen", 0f },
11-
{ "/jawForward", 0f },
12-
{ "/jawLeft", 0f },
13-
{ "/jawRight", 0f },
14-
{ "/noseSneerLeft", 0f },
15-
{ "/noseSnerrRight", 0f },
16-
{ "/mouthFunnel", 0f },
17-
{ "/mouthPucker", 0f },
18-
{ "/mouthLeft", 0f },
19-
{ "/mouthRight", 0f },
20-
{ "/mouthRollUpper", 0f },
21-
{ "/mouthRollLower", 0f },
22-
{ "/mouthShrugUpper", 0f },
23-
{ "/mouthShrugLower", 0f },
24-
{ "/mouthClose", 0f },
25-
{ "/mouthSmileLeft", 0f },
26-
{ "/mouthSmileRight", 0f },
27-
{ "/mouthFrownLeft", 0f },
28-
{ "/mouthFrownRight", 0f },
29-
{ "/mouthDimpleLeft", 0f },
30-
{ "/mouthDimpleRight", 0f },
31-
{ "/mouthUpperUpLeft", 0f },
32-
{ "/mouthUpperUpRight", 0f },
33-
{ "/mouthLowerDownLeft", 0f },
34-
{ "/mouthLowerDownRight", 0f },
35-
{ "/mouthPressLeft", 0f },
36-
{ "/mouthPressRight", 0f },
37-
{ "/mouthStretchLeft", 0f },
38-
{ "/mouthStretchRight", 0f },
39-
{ "/tongueOut", 0f },
40-
{ "/tongueUp", 0f },
41-
{ "/tongueDown", 0f },
42-
{ "/tongueLeft", 0f },
43-
{ "/tongueRight", 0f },
44-
{ "/tongueRoll", 0f },
45-
{ "/tongueBendDown", 0f },
46-
{ "/tongueCurlUp", 0f },
47-
{ "/tongueSquish", 0f },
48-
{ "/tongueFlat", 0f },
49-
{ "/tongueTwistLeft", 0f },
50-
{ "/tognueTwistRight", 0f }
14+
var expressions = Path.Combine(
15+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
16+
BabbleExpressionsPath);
17+
var converter = new TwoKeyDictionaryConverter<UnifiedExpressions, string, float>();
18+
if (!File.Exists(expressions))
19+
{
20+
string json = JsonConvert.SerializeObject(
21+
DefaultBabbleExpressionMap, converter);
22+
File.WriteAllText(expressions, json);
23+
}
24+
25+
BabbleExpressionMap = JsonConvert.DeserializeObject
26+
<TwoKeyDictionary<UnifiedExpressions, string, float>>
27+
(File.ReadAllText(expressions), converter)!;
28+
}
29+
30+
private static readonly TwoKeyDictionary<UnifiedExpressions, string, float> DefaultBabbleExpressionMap = new()
31+
{
32+
{ UnifiedExpressions.CheekPuffLeft, "/cheekPuffLeft", 0f },
33+
{ UnifiedExpressions.CheekPuffRight, "/cheekPuffRight", 0f },
34+
{ UnifiedExpressions.CheekSuckLeft, "/cheekSuckLeft", 0f },
35+
{ UnifiedExpressions.CheekSuckRight, "/cheekSuckRight", 0f },
36+
{ UnifiedExpressions.JawOpen, "/jawOpen", 0f },
37+
{ UnifiedExpressions.JawForward, "/jawForward", 0f },
38+
{ UnifiedExpressions.JawLeft, "/jawLeft", 0f },
39+
{ UnifiedExpressions.JawRight, "/jawRight", 0f },
40+
{ UnifiedExpressions.NoseSneerLeft, "/noseSneerLeft", 0f },
41+
{ UnifiedExpressions.NoseSneerRight, "/noseSneerRight", 0f },
42+
{ UnifiedExpressions.LipFunnelLowerLeft, "/mouthFunnel", 0f },
43+
{ UnifiedExpressions.LipFunnelLowerRight, "/mouthFunnel", 0f },
44+
{ UnifiedExpressions.LipFunnelUpperLeft, "/mouthFunnel", 0f },
45+
{ UnifiedExpressions.LipFunnelUpperRight, "/mouthFunnel", 0f },
46+
{ UnifiedExpressions.LipPuckerLowerLeft, "/mouthPucker", 0f },
47+
{ UnifiedExpressions.LipPuckerLowerRight, "/mouthPucker", 0f },
48+
{ UnifiedExpressions.LipPuckerUpperLeft, "/mouthPucker", 0f },
49+
{ UnifiedExpressions.LipPuckerUpperRight, "/mouthPucker", 0f },
50+
{ UnifiedExpressions.MouthPressLeft, "/mouthLeft", 0f },
51+
{ UnifiedExpressions.MouthPressRight, "/mouthRight", 0f },
52+
{ UnifiedExpressions.LipSuckUpperLeft, "/mouthRollUpper", 0f },
53+
{ UnifiedExpressions.LipSuckUpperRight, "/mouthRollUpper", 0f },
54+
{ UnifiedExpressions.LipSuckLowerLeft, "/mouthRollLower", 0f },
55+
{ UnifiedExpressions.LipSuckLowerRight, "/mouthRollLower", 0f },
56+
{ UnifiedExpressions.MouthRaiserUpper, "/mouthShrugUpper", 0f },
57+
{ UnifiedExpressions.MouthRaiserLower, "/mouthShrugLower", 0f },
58+
{ UnifiedExpressions.MouthClosed, "/mouthClose", 0f },
59+
{ UnifiedExpressions.MouthCornerPullLeft, "/mouthSmileLeft", 0f },
60+
{ UnifiedExpressions.MouthCornerPullRight, "/mouthSmileRight", 0f },
61+
{ UnifiedExpressions.MouthFrownLeft, "/mouthFrownLeft", 0f },
62+
{ UnifiedExpressions.MouthFrownRight, "/mouthFrownRight", 0f },
63+
{ UnifiedExpressions.MouthDimpleLeft, "/mouthDimpleLeft", 0f },
64+
{ UnifiedExpressions.MouthDimpleRight, "/mouthDimpleRight", 0f },
65+
{ UnifiedExpressions.MouthUpperUpLeft, "/mouthUpperUpLeft", 0f },
66+
{ UnifiedExpressions.MouthUpperUpRight, "/mouthUpperUpRight", 0f },
67+
{ UnifiedExpressions.MouthLowerDownLeft, "/mouthLowerDownLeft", 0f },
68+
{ UnifiedExpressions.MouthLowerDownRight, "/mouthLowerDownRight", 0f },
69+
{ UnifiedExpressions.MouthPressLeft, "/mouthPressLeft", 0f },
70+
{ UnifiedExpressions.MouthPressRight, "/mouthPressRight", 0f },
71+
{ UnifiedExpressions.MouthStretchLeft, "/mouthStretchLeft", 0f },
72+
{ UnifiedExpressions.MouthStretchRight, "/mouthStretchRight", 0f },
73+
{ UnifiedExpressions.TongueOut, "/tongueOut", 0f },
74+
{ UnifiedExpressions.TongueUp, "/tongueUp", 0f },
75+
{ UnifiedExpressions.TongueDown, "/tongueDown", 0f },
76+
{ UnifiedExpressions.TongueLeft, "/tongueLeft", 0f },
77+
{ UnifiedExpressions.TongueRight, "/tongueRight", 0f },
78+
{ UnifiedExpressions.TongueRoll, "/tongueRoll", 0f },
79+
{ UnifiedExpressions.TongueBendDown, "/tongueBendDown", 0f },
80+
{ UnifiedExpressions.TongueCurlUp, "/tongueCurlUp", 0f },
81+
{ UnifiedExpressions.TongueSquish, "/tongueSquish", 0f },
82+
{ UnifiedExpressions.TongueFlat, "/tongueFlat", 0f },
83+
{ UnifiedExpressions.TongueTwistLeft, "/tongueTwistLeft", 0f },
84+
{ UnifiedExpressions.TongueTwistRight, "/tongueTwistRight", 0 }
5185
};
5286
}

BabbleOSC.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
using Microsoft.Extensions.Logging;
12
using System.Net;
23
using System.Net.Sockets;
3-
using Microsoft.Extensions.Logging;
4-
using Newtonsoft.Json.Linq;
5-
using VRCFaceTracking.Core.OSC;
64

75
namespace VRCFaceTracking.Babble;
8-
public partial class BabbleOSC
6+
7+
public class BabbleOSC
98
{
109
private Socket _receiver;
1110
private bool _loop = true;
@@ -142,9 +141,9 @@ private void ListenLoop()
142141
var length = _receiver.Receive(buffer);
143142

144143
Msg msg = ParseOSC(buffer, length);
145-
if (msg.success && BabbleExpressionMap.ContainsKey(msg.address))
144+
if (msg.success && BabbleExpressions.BabbleExpressionMap.ContainsKey2(msg.address))
146145
{
147-
BabbleExpressionMap[msg.address] = msg.value;
146+
BabbleExpressions.BabbleExpressionMap.SetByKey2(msg.address, msg.value);
148147
}
149148
}
150149
else

BabbleVRC.cs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Reflection;
2+
using VRCFaceTracking.Core.Params.Data;
23
using VRCFaceTracking.Core.Params.Expressions;
34

45
namespace VRCFaceTracking.Babble;
@@ -16,7 +17,7 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
1617
Assembly a = Assembly.GetExecutingAssembly();
1718
var hmdStream = a.GetManifestResourceStream
1819
("VRCFaceTracking.Babble.BabbleLogo.png");
19-
streams.Add(hmdStream);
20+
streams.Add(hmdStream!);
2021
ModuleInformation = new ModuleMetadata()
2122
{
2223
Name = "Project Babble Face Tracking\nInference Model v2.0.0",
@@ -29,44 +30,9 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
2930
public override void Teardown() => babbleOSC.Teardown();
3031
public override void Update()
3132
{
32-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.TongueOut].Weight = babbleOSC.BabbleExpressionMap["/tongueOut"];
33-
34-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.JawOpen].Weight = babbleOSC.BabbleExpressionMap["/jawOpen"];
35-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.JawLeft].Weight = -babbleOSC.BabbleExpressionMap["/jawLeft"];
36-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.JawRight].Weight = -babbleOSC.BabbleExpressionMap["/jawRight"];
37-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.JawForward].Weight = babbleOSC.BabbleExpressionMap["/jawForward"];
38-
39-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.NoseSneerLeft].Weight = -babbleOSC.BabbleExpressionMap["/noseSneerLeft"];
40-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.NoseSneerRight].Weight = -babbleOSC.BabbleExpressionMap["/noseSneerRight"];
41-
42-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipPuckerLowerLeft].Weight = babbleOSC.BabbleExpressionMap["/mouthPucker"];
43-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipPuckerLowerRight].Weight = babbleOSC.BabbleExpressionMap["/mouthPucker"];
44-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipPuckerUpperLeft].Weight = babbleOSC.BabbleExpressionMap["/mouthPucker"];
45-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipPuckerUpperRight].Weight = babbleOSC.BabbleExpressionMap["/mouthPucker"];
46-
47-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipFunnelLowerLeft].Weight = babbleOSC.BabbleExpressionMap["/mouthFunnel"];
48-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipFunnelLowerRight].Weight = babbleOSC.BabbleExpressionMap["/mouthFunnel"];
49-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipFunnelUpperLeft].Weight = babbleOSC.BabbleExpressionMap["/mouthFunnel"];
50-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.LipFunnelUpperRight].Weight = babbleOSC.BabbleExpressionMap["/mouthFunnel"];
51-
52-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthUpperUpLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthUpperUpLeft"];
53-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthUpperUpRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthUpperUpRight"];
54-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthLowerDownLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthLowerDownLeft"];
55-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthLowerDownRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthLowerDownRight"];
56-
57-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthPressLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthPressLeft"];
58-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthPressRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthPressRight"];
59-
60-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthStretchLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthStretchLeft"];
61-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthStretchRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthStretchRight"];
62-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthDimpleLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthDimpleLeft"];
63-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthDimpleRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthDimpleRight"];
64-
65-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthCornerPullLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthSmileLeft"];
66-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthCornerPullRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthSmileRight"];
67-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthFrownLeft].Weight = -babbleOSC.BabbleExpressionMap["/mouthFrownLeft"];
68-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.MouthFrownRight].Weight = -babbleOSC.BabbleExpressionMap["/mouthFrownRight"];
69-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.CheekPuffLeft].Weight = babbleOSC.BabbleExpressionMap["/cheekPuff"];
70-
UnifiedTracking.Data.Shapes[(int)UnifiedExpressions.CheekPuffRight].Weight = babbleOSC.BabbleExpressionMap["/cheekPuff"];
33+
foreach (var unifiedExpression in BabbleExpressions.BabbleExpressionMap)
34+
{
35+
UnifiedTracking.Data.Shapes[(int) unifiedExpression].Weight = BabbleExpressions.BabbleExpressionMap.GetByKey1 (unifiedExpression);
36+
}
7137
}
7238
}

0 commit comments

Comments
 (0)