Skip to content

Commit

Permalink
feat: ✨ Support FB face tracking 2; fix eye tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Dec 24, 2023
1 parent fd19203 commit 302c5a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
41 changes: 30 additions & 11 deletions ALVRModule/ALVRModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public enum FaceFb
UpperLidRaiserR = 60,
UpperLipRaiserL = 61,
UpperLipRaiserR = 62,
FaceFbMax = 63
TongueTipInterdental = 63,
TongueTipAlveolar = 64,
TongueFrontDorsalPalate = 65,
TongueMidDorsalPalate = 66,
TongueBackDorsalVelar = 67,
TongueOutFb = 68,
TongueRetreat = 69,
Face1FbMax = 63,
Face2FbMax = 70,
}

public class ALVRModule : ExtTrackingModule
Expand Down Expand Up @@ -171,20 +179,21 @@ private static void SetCombEyesQuatParams(float[] p)
SetEyesQuatParams(array);
}

private static void SetFaceFbParams(float[] p)
static void SetParam(float[] data, FaceFb input, UnifiedExpressions outputType)
{
Debug.Assert(p.Length == (int)FaceFbMax);
UnifiedTracking.Data.Shapes[(int)outputType].Weight = data[(int)input];
}

private static void SetFace1FbParams(float[] p)
{
// Debug.Assert(p.Length == (int)Face1FbMax);

var eye = UnifiedTracking.Data.Eye;
var expr = UnifiedTracking.Data.Shapes;

eye.Left.Openness = 1.0f - (float)Math.Max(0, Math.Min(1, p[(int)EyesClosedL] + p[(int)EyesClosedL] * p[(int)LidTightenerL]));
eye.Right.Openness = 1.0f - (float)Math.Max(0, Math.Min(1, p[(int)EyesClosedR] + p[(int)EyesClosedR] * p[(int)LidTightenerR]));

static void SetParam(float[] data, FaceFb input, UnifiedExpressions outputType)
{
UnifiedTracking.Data.Shapes[(int)outputType].Weight = data[(int)input];
}

// Eyelids
SetParam(p, LidTightenerR, EyeSquintRight);
Expand Down Expand Up @@ -266,7 +275,6 @@ static void SetParam(float[] data, FaceFb input, UnifiedExpressions outputType)
SetParam(p, DimplerL, MouthDimpleLeft);
SetParam(p, DimplerR, MouthDimpleRight);


SetParam(p, ChinRaiserT, MouthRaiserUpper);
SetParam(p, ChinRaiserB, MouthRaiserLower);
SetParam(p, LipPressorR, MouthPressRight);
Expand All @@ -275,6 +283,14 @@ static void SetParam(float[] data, FaceFb input, UnifiedExpressions outputType)
SetParam(p, LipTightenerL, MouthTightenerLeft);
}

private static void SetFace2FbParams(float[] p) {
Debug.Assert(p.Length == (int)Face2FbMax);

SetFace1FbParams(p);

SetParam(p, TongueOutFb, TongueOut);
}

public override void Update()
{
byte[] packet;
Expand All @@ -297,13 +313,16 @@ public override void Update()
switch (str)
{
case "EyesQuat":
SetFaceFbParams(GetParams(packet, ref cursor, 8));
SetEyesQuatParams(GetParams(packet, ref cursor, 8));
break;
case "CombQuat":
SetFaceFbParams(GetParams(packet, ref cursor, 4));
SetCombEyesQuatParams(GetParams(packet, ref cursor, 4));
break;
case "FaceFb\0\0":
SetFaceFbParams(GetParams(packet, ref cursor, (int)FaceFbMax));
SetFace1FbParams(GetParams(packet, ref cursor, (int)Face1FbMax));
break;
case "Face2Fb\0":
SetFace2FbParams(GetParams(packet, ref cursor, (int)Face2FbMax));
break;
default:
Logger.LogError("[ALVR Module] Unrecognized prefix");
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"DllFileName": "ALVRModule.dll",
"Downloads": 0,
"DownloadUrl": "https://github.com/alvr-org/VRCFT-ALVR/releases/download/v1.2.0/ALVRModule.zip",
"LastUpdated": "2023-11-08T07:36:37Z",
"LastUpdated": "2023-12-24T18:33:19Z",
"ModuleDescription": "VRCFaceTracking module for ALVR support",
"ModuleName": "ALVR Module",
"ModulePageUrl": "https://github.com/alvr-org/VRCFT-ALVR",
Expand Down

0 comments on commit 302c5a0

Please sign in to comment.