From 44e0a69fac7c950f79c780a51a9f9dae10a31ba9 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 19 Feb 2022 00:17:21 +0000 Subject: [PATCH] Removed unnecessary data from global update delegate. Got rid of extra data stored in UnifiedTrackingData --- VRCFaceTracking/MainStandalone.cs | 5 ++--- VRCFaceTracking/OSC/OSCMain.cs | 7 ++++--- VRCFaceTracking/Params/Lip/LipShapeMerger.cs | 4 ++-- VRCFaceTracking/Params/ParamContainers.cs | 8 ++++---- .../TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs | 3 ++- .../SRanipal/SRanipalTrackingInterface.cs | 13 +++++++++---- VRCFaceTracking/UnifiedTrackingData.cs | 4 ++-- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/VRCFaceTracking/MainStandalone.cs b/VRCFaceTracking/MainStandalone.cs index ed77c0d6..04c9a0bd 100644 --- a/VRCFaceTracking/MainStandalone.cs +++ b/VRCFaceTracking/MainStandalone.cs @@ -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; @@ -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); } } diff --git a/VRCFaceTracking/OSC/OSCMain.cs b/VRCFaceTracking/OSC/OSCMain.cs index e83bc04b..ffda7273 100644 --- a/VRCFaceTracking/OSC/OSCMain.cs +++ b/VRCFaceTracking/OSC/OSCMain.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Sockets; namespace VRCFaceTracking.OSC @@ -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); } } \ No newline at end of file diff --git a/VRCFaceTracking/Params/Lip/LipShapeMerger.cs b/VRCFaceTracking/Params/Lip/LipShapeMerger.cs index 767c6f81..de0bd19f 100644 --- a/VRCFaceTracking/Params/Lip/LipShapeMerger.cs +++ b/VRCFaceTracking/Params/Lip/LipShapeMerger.cs @@ -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)}, @@ -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 diff --git a/VRCFaceTracking/Params/ParamContainers.cs b/VRCFaceTracking/Params/ParamContainers.cs index 18c3d1fe..f2ad1099 100644 --- a/VRCFaceTracking/Params/ParamContainers.cs +++ b/VRCFaceTracking/Params/ParamContainers.cs @@ -10,9 +10,9 @@ public class FloatParameter : FloatBaseParam, IParameter public FloatParameter(Func, 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; @@ -29,7 +29,7 @@ public class XYParameter : XYParam, IParameter { public XYParameter(Func, 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); @@ -57,7 +57,7 @@ public class BoolParameter : BoolBaseParam, IParameter { public BoolParameter(Func, bool?> getValueFunc, string paramName) : base(paramName) => - UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lipFloats, lip) => + UnifiedTrackingData.OnUnifiedParamsUpdated += (eye, lip) => { #if DLL if (!UnifiedLibManager.EyeEnabled && !UnifiedLibManager.LipEnabled) return; diff --git a/VRCFaceTracking/TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs b/VRCFaceTracking/TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs index 6f927126..5c722946 100644 --- a/VRCFaceTracking/TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs +++ b/VRCFaceTracking/TrackingLibs/SRanipal/Lip/SRanipal_Lip_v2.cs @@ -46,10 +46,11 @@ private static bool UpdateData() /// /// Weighting values obtained from anipal's Lip module. /// Indicates whether the values received are new. - public static bool GetLipWeightings(out Dictionary shapes) + public static bool GetLipWeightingsAndImage(out Dictionary shapes, out IntPtr image) { bool update = UpdateData(); shapes = Weightings; + image = LipData.image; return update; } diff --git a/VRCFaceTracking/TrackingLibs/SRanipal/SRanipalTrackingInterface.cs b/VRCFaceTracking/TrackingLibs/SRanipal/SRanipalTrackingInterface.cs index 28fbf90d..e74dfec7 100644 --- a/VRCFaceTracking/TrackingLibs/SRanipal/SRanipalTrackingInterface.cs +++ b/VRCFaceTracking/TrackingLibs/SRanipal/SRanipalTrackingInterface.cs @@ -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); } @@ -90,6 +92,7 @@ public void Teardown() } #region Update + public Action GetUpdateThreadFunc() { @@ -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 diff --git a/VRCFaceTracking/UnifiedTrackingData.cs b/VRCFaceTracking/UnifiedTrackingData.cs index ef7de807..864f6675 100644 --- a/VRCFaceTracking/UnifiedTrackingData.cs +++ b/VRCFaceTracking/UnifiedTrackingData.cs @@ -111,14 +111,14 @@ public struct UnifiedTrackingData public static readonly List AllParameters = EyeTrackingParams.ParameterList.Union(LipShapeMerger.AllLipParameters).ToList(); // Central update action for all parameters to subscribe to - public static Action /* 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 LatestLipShapes = new Dictionary(); } } \ No newline at end of file