Skip to content

Commit

Permalink
Removed unnecessary data from global update delegate. Got rid of extr…
Browse files Browse the repository at this point in the history
…a data stored in UnifiedTrackingData
  • Loading branch information
benaclejames committed Feb 19, 2022
1 parent 30dce2f commit 44e0a69
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
5 changes: 2 additions & 3 deletions VRCFaceTracking/MainStandalone.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using ParamLib;
using VRCFaceTracking.OSC;
using VRCFaceTracking.Params;
Expand All @@ -24,14 +23,14 @@ public static void Main()
Logger.Msg("Initialized UnifiedLibManager Successfully");

var allParams = UnifiedTrackingData.AllParameters.SelectMany(param => param.GetBase().Where(b => b.GetType() == typeof(FloatParameter) || b.GetType() == typeof(FloatBaseParam)));

while (true)
{
Thread.Sleep(10);
UnifiedTrackingData.OnUnifiedParamsUpdated.Invoke(UnifiedTrackingData.LatestEyeData,
UnifiedTrackingData.LatestLipData.prediction_data.blend_shape_weight,
UnifiedTrackingData.LatestLipShapes);

var bundle = new OscBundle(ConstructMessages(allParams));

OSCMain.Send(bundle.Data);
}
}
Expand Down
7 changes: 4 additions & 3 deletions VRCFaceTracking/OSC/OSCMain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Sockets;

namespace VRCFaceTracking.OSC
Expand All @@ -21,10 +22,10 @@ public static byte[] EnsureCompliance(this byte[] inputArr)
return newArr;
}

private static readonly UdpClient UdpClient = new UdpClient();
private static readonly Socket UdpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
private static int Port = 9000;

static OSCMain() => UdpClient.Connect("127.0.0.1", Port);
public static void Send(byte[] data) => UdpClient.Send(data, data.Length);
static OSCMain() => UdpClient.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), Port));
public static void Send(byte[] data) => UdpClient.Send(data, data.Length, SocketFlags.None);
}
}
4 changes: 2 additions & 2 deletions VRCFaceTracking/Params/Lip/LipShapeMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class LipShapeMerger
{"SmileSad", new PositiveNegativeAveragedShape(new LipShape_v2[]{LipShape_v2.MouthSmileLeft, LipShape_v2.MouthSmileRight}, new LipShape_v2[]{LipShape_v2.MouthSadLeft, LipShape_v2.MouthSadRight})},
{"TongueY", new PositiveNegativeShape(LipShape_v2.TongueUp, LipShape_v2.TongueDown)},
{"TongueX", new PositiveNegativeShape(LipShape_v2.TongueRight, LipShape_v2.TongueLeft)},
{"PuffSuckRight", new PositiveNegativeShape(LipShape_v2.CheekPuffRight, LipShape_v2.CheekSuck)},
/*{"PuffSuckRight", new PositiveNegativeShape(LipShape_v2.CheekPuffRight, LipShape_v2.CheekSuck)},
{"PuffSuckLeft", new PositiveNegativeShape(LipShape_v2.CheekPuffLeft, LipShape_v2.CheekSuck)},
{"PuffSuck", new PositiveNegativeAveragedShape(new LipShape_v2[]{LipShape_v2.CheekPuffLeft, LipShape_v2.CheekPuffRight}, new LipShape_v2[]{LipShape_v2.CheekSuck}, true)},
Expand Down Expand Up @@ -122,7 +122,7 @@ public static class LipShapeMerger
{"PuffOverturn", new PositiveNegativeAveragedShape(new LipShape_v2[]{LipShape_v2.CheekPuffRight, LipShape_v2.CheekPuffLeft}, new LipShape_v2[]{LipShape_v2.MouthUpperOverturn, LipShape_v2.MouthLowerOverturn}, true)},
//Combine both TongueSteps (-1 fully in, 0 on edge, 1 fully out)
{"TongueSteps", new PositiveNegativeShape(LipShape_v2.TongueLongStep1, LipShape_v2.TongueLongStep2, true)},
{"TongueSteps", new PositiveNegativeShape(LipShape_v2.TongueLongStep1, LipShape_v2.TongueLongStep2, true)},*/
};

// Make a list called LipParameters containing the results from both GetOptimizedLipParameters and GetAllLipParameters
Expand Down
8 changes: 4 additions & 4 deletions VRCFaceTracking/Params/ParamContainers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class FloatParameter : FloatBaseParam, IParameter
public FloatParameter(Func<EyeTrackingData, Dictionary<LipShape_v2, float>, float?> getValueFunc,
string paramName, bool wantsPriority = false)
: base(paramName, wantsPriority) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lipFloats, lip) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lip) =>
{
if (!UnifiedLibManager.EyeEnabled && !UnifiedLibManager.LipEnabled) return;
//if (!UnifiedLibManager.EyeEnabled && !UnifiedLibManager.LipEnabled) return;
var value = getValueFunc.Invoke(eye, lip);
if (value.HasValue)
ParamValue = value.Value;
Expand All @@ -29,7 +29,7 @@ public class XYParameter : XYParam, IParameter
{
public XYParameter(Func<EyeTrackingData, Dictionary<LipShape_v2, float>, Vector2?> getValueFunc, string xParamName, string yParamName)
: base(new FloatBaseParam(xParamName, true), new FloatBaseParam(yParamName, true)) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lipFloats, lip) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lip) =>
{
if (!UnifiedLibManager.EyeEnabled && !UnifiedLibManager.LipEnabled) return;
var value = getValueFunc.Invoke(eye, lip);
Expand Down Expand Up @@ -57,7 +57,7 @@ public class BoolParameter : BoolBaseParam, IParameter
{
public BoolParameter(Func<EyeTrackingData, Dictionary<LipShape_v2, float>, bool?> getValueFunc,
string paramName) : base(paramName) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lipFloats, lip) =>
UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lip) =>
{
#if DLL
if (!UnifiedLibManager.EyeEnabled && !UnifiedLibManager.LipEnabled) return;
Expand Down
3 changes: 2 additions & 1 deletion VRCFaceTracking/TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ private static bool UpdateData()
/// </summary>
/// <param name="shapes">Weighting values obtained from anipal's Lip module.</param>
/// <returns>Indicates whether the values received are new.</returns>
public static bool GetLipWeightings(out Dictionary<LipShape_v2, float> shapes)
public static bool GetLipWeightingsAndImage(out Dictionary<LipShape_v2, float> shapes, out IntPtr image)
{
bool update = UpdateData();
shapes = Weightings;
image = LipData.image;
return update;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public class SRanipalTrackingInterface : ITrackingModule
}
}

#if DLL
if (lipEnabled)
UnifiedTrackingData.LatestLipData.image = Marshal.AllocCoTaskMem(SRanipal_Lip_v2.ImageWidth * SRanipal_Lip_v2.ImageHeight);

UnifiedTrackingData.Image = Marshal.AllocCoTaskMem(SRanipal_Lip_v2.ImageWidth * SRanipal_Lip_v2.ImageHeight);
#endif

return (eyeEnabled, lipEnabled);
}

Expand Down Expand Up @@ -90,6 +92,7 @@ public void Teardown()
}

#region Update


public Action GetUpdateThreadFunc()
{
Expand Down Expand Up @@ -173,11 +176,13 @@ private void UpdateEye()
#endif
}

private int lastUpdate;
public static int diff;

private void UpdateMouth()
{
if (!UnifiedLibManager.LipEnabled) return;
SRanipal_Lip_API.GetLipData_v2(ref UnifiedTrackingData.LatestLipData);
SRanipal_Lip_v2.GetLipWeightings(out UnifiedTrackingData.LatestLipShapes);
SRanipal_Lip_v2.GetLipWeightingsAndImage(out UnifiedTrackingData.LatestLipShapes, out UnifiedTrackingData.Image);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions VRCFaceTracking/UnifiedTrackingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public struct UnifiedTrackingData
public static readonly List<IParameter> AllParameters = EyeTrackingParams.ParameterList.Union(LipShapeMerger.AllLipParameters).ToList();

// Central update action for all parameters to subscribe to
public static Action<EyeTrackingData, float[] /* Lip Data Blend Shape */
public static Action<EyeTrackingData /* Lip Data Blend Shape */
, Dictionary<LipShape_v2, float> /* Lip Weightings */> OnUnifiedParamsUpdated;

// Copy of latest updated unified eye data
public static EyeTrackingData LatestEyeData;

// SRanipal Exclusives
public static LipData_v2 LatestLipData;
public static IntPtr Image;
public static Dictionary<LipShape_v2, float> LatestLipShapes = new Dictionary<LipShape_v2, float>();
}
}

0 comments on commit 44e0a69

Please sign in to comment.