1
1
namespace BFI_VRCFT_Module
2
2
{
3
3
using Microsoft . Extensions . Logging ;
4
+ using System . Linq . Expressions ;
5
+ using System . Net ;
4
6
using System . Text . Json ;
5
7
using System . Text . Json . Serialization ;
6
8
using VRCFaceTracking ;
@@ -22,7 +24,7 @@ public class BFI_VRCFT_Module : ExtTrackingModule
22
24
23
25
//osc info
24
26
public static bool debug = false ;
25
- OscReceiver reciever = new OscReceiver ( 8999 ) ;
27
+ OscReceiver reciever ;
26
28
27
29
//expressions
28
30
UnifiedExpressionShape frown = new UnifiedExpressionShape ( ) ;
@@ -32,6 +34,8 @@ public class BFI_VRCFT_Module : ExtTrackingModule
32
34
UnifiedExpressionShape browDown = new UnifiedExpressionShape ( ) ;
33
35
UnifiedExpressionShape cheekPuff = new UnifiedExpressionShape ( ) ;
34
36
UnifiedExpressionShape apeShape = new UnifiedExpressionShape ( ) ;
37
+ UnifiedExpressionShape browInnerUp = new UnifiedExpressionShape ( ) ;
38
+ UnifiedExpressionShape browOuterUp = new UnifiedExpressionShape ( ) ;
35
39
36
40
37
41
// What your interface is able to send as tracking data.
@@ -43,7 +47,23 @@ public class BFI_VRCFT_Module : ExtTrackingModule
43
47
public override ( bool eyeSuccess , bool expressionSuccess ) Initialize ( bool eyeAvailable , bool expressionAvailable )
44
48
{
45
49
50
+ JsonParser parser = new JsonParser ( ) ;
51
+ Config config = new Config ( ) ;
52
+ try
53
+ {
54
+ config = parser . ParseConfig ( ) ;
55
+ }
56
+ catch ( Exception ex )
57
+ {
58
+ Logger . LogInformation ( $ "Error parsing JSON file: { ex . Message } ") ;
59
+ }
60
+
61
+ Logger . LogInformation ( parser . debugString ) ;
62
+
63
+ reciever = new OscReceiver ( IPAddress . Parse ( config . ip ) , config . port , config . timoutTime ) ;
64
+
46
65
reciever . StartListening ( ) ; //starts OSC listener
66
+ Logger . LogInformation ( reciever . debugString ) ;
47
67
var state = ( eyeAvailable , expressionAvailable ) ;
48
68
49
69
ModuleInformation . Name = "BFI Module" ;
@@ -60,10 +80,9 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
60
80
//parsing json file for expressions
61
81
try
62
82
{
63
-
64
- JsonParser parser = new JsonParser ( ) ;
65
- SupportedExpressions expressions = parser . ParseJson ( ) ; //parsing json file
83
+ SupportedExpressions expressions = parser . ParseExpressions ( ) ; //parsing json file
66
84
reciever . expressions = expressions ; //assigning expressions to the reciever
85
+
67
86
if ( expressions != null && expressions . Expressions != null )
68
87
{
69
88
if ( expressions . Expressions != null )
@@ -78,6 +97,7 @@ public override (bool eyeSuccess, bool expressionSuccess) Initialize(bool eyeAva
78
97
{
79
98
Logger . LogInformation ( $ "No expressions found in the JSON file") ;
80
99
}
100
+
81
101
}
82
102
catch ( Exception ex )
83
103
{
@@ -101,7 +121,7 @@ public override void Update()
101
121
// ... Execute update cycle.
102
122
103
123
104
- if ( debug ) Logger . LogInformation ( reciever . OSCDebugData ) ;
124
+ if ( debug ) Logger . LogInformation ( reciever . debugString ) ;
105
125
106
126
//UpdateValues();
107
127
UpdateValuesExpressions ( ) ;
@@ -154,10 +174,10 @@ public override void Update()
154
174
UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . JawOpen ] = apeShape ;
155
175
UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . MouthClosed ] = apeShape ;
156
176
157
- UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpLeft ] = apeShape ;
158
- UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpRight ] = apeShape ;
159
- UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpLeft ] = apeShape ;
160
- UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpRight ] = apeShape ;
177
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpLeft ] = browInnerUp ;
178
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpRight ] = browInnerUp ;
179
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpLeft ] = browOuterUp ;
180
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpRight ] = browOuterUp ;
161
181
162
182
163
183
@@ -167,19 +187,6 @@ public override void Update()
167
187
Thread . Sleep ( 10 ) ;
168
188
}
169
189
170
- /*private void UpdateValues()//legacy function, easier to read
171
- {
172
- frown.Weight = reciever.frown + (-reciever.smile);
173
-
174
- mouthUpperUp.Weight = reciever.smile;
175
-
176
- mouthLowerDown.Weight = Math.Clamp(reciever.smile + reciever.cringe, 0, 1);
177
-
178
- browDown.Weight = reciever.anger;
179
-
180
- MouthStretch.Weight = reciever.cringe;
181
- }*/
182
-
183
190
private void UpdateValuesExpressions ( ) //sets values of expressions based on the values recieved from OSC if present
184
191
{
185
192
try
@@ -212,7 +219,14 @@ public override void Update()
212
219
{
213
220
mouthLowerDown . Weight = Clampf01 ( reciever . expressions . Expressions [ tagCringe ] . Weight ) ;
214
221
}
222
+
223
+ if ( ! reciever . expressions . Expressions . ContainsKey ( tagApeShape ) )
224
+ {
225
+ browInnerUp . Weight = Clampf01 ( reciever . expressions . Expressions [ tagCringe ] . Weight ) ;
226
+ }
227
+
215
228
MouthStretch . Weight = Clampf01 ( reciever . expressions . Expressions [ tagCringe ] . Weight ) ;
229
+
216
230
}
217
231
if ( reciever . expressions . Expressions . ContainsKey ( tagAnger ) )
218
232
{
@@ -225,6 +239,17 @@ public override void Update()
225
239
if ( reciever . expressions . Expressions . ContainsKey ( tagApeShape ) )
226
240
{
227
241
apeShape . Weight = Clampf01 ( reciever . expressions . Expressions [ tagApeShape ] . Weight ) ;
242
+
243
+ if ( reciever . expressions . Expressions . ContainsKey ( tagCringe ) )
244
+ {
245
+ browInnerUp . Weight = Clampf01 ( reciever . expressions . Expressions [ tagCringe ] . Weight + reciever . expressions . Expressions [ tagApeShape ] . Weight ) ;
246
+
247
+ }
248
+ else
249
+ {
250
+ browInnerUp . Weight = Clampf01 ( reciever . expressions . Expressions [ tagApeShape ] . Weight ) ;
251
+ }
252
+ browOuterUp . Weight = Clampf01 ( reciever . expressions . Expressions [ tagApeShape ] . Weight ) ;
228
253
}
229
254
230
255
}
@@ -249,6 +274,10 @@ public override void Teardown()
249
274
browDown . Weight = 0 ;
250
275
MouthStretch . Weight = 0 ;
251
276
cheekPuff . Weight = 0 ;
277
+ apeShape . Weight = 0 ;
278
+ browInnerUp . Weight = 0 ;
279
+ browOuterUp . Weight = 0 ;
280
+
252
281
253
282
UnifiedTracking . Data . Eye . Left . Openness = 1 ;
254
283
UnifiedTracking . Data . Eye . Right . Openness = 1 ;
@@ -270,6 +299,14 @@ public override void Teardown()
270
299
UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . CheekPuffRight ] = cheekPuff ;
271
300
UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . CheekPuffLeft ] = cheekPuff ;
272
301
302
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . JawOpen ] = apeShape ;
303
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . MouthClosed ] = apeShape ;
304
+
305
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpLeft ] = browInnerUp ;
306
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowInnerUpRight ] = browInnerUp ;
307
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpLeft ] = browOuterUp ;
308
+ UnifiedTracking . Data . Shapes [ ( int ) UnifiedExpressions . BrowOuterUpRight ] = browOuterUp ;
309
+
273
310
}
274
311
275
312
float map ( float x , float in_min , float in_max , float out_min , float out_max ) //remapping function, could prove useful
0 commit comments