How do I get FaceTrackNoIR's input in Unity?
I have recently obtained FaceTrackNoIR v200 and have it set up and working for at least one game (Elite Dangerous). I already have full working VR menu that works with the SteamVR asset . The scene can handle both having and not having an HMD.
I am wondering how I can use FTNIR's input data in my Unity project
Answer by Psyco92 · Jun 01, 2016 at 01:47 PM
After much hunting, I found the following source and converted it to work with the 64bit version. The data will need to be smoothed and manipulated to work nicely, it seems very raw at the moment.
Go to : C:\Program Files (x86)\Abbequerque Inc\FaceTrackNoIR_v200 And copy : FreeTrackClient64.dll Into your Unity project under : Assets\Plugins Create a script called FreeTrackClientDll and replace its contents with the following :
using System;
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class FreeTrackClientDll : MonoBehaviour
{
[StructLayout(LayoutKind.Sequential)]
public struct FreeTrackData
{
public int dataid;
public int camwidth, camheight;
public Single Yaw, Pitch, Roll, X, Y, Z;
public Single RawYaw, RawPitch, RawRoll;
public Single RawX, RawY, RawZ;
public Single x1, y1, x2, y2, x3, y3, x4, y4;
}
[DllImport("FreeTrackClient64")]
public static extern bool FTGetData(ref FreeTrackData data);
[DllImport("FreeTrackClient64")]
public static extern string FTGetDllVersion();
[DllImport("FreeTrackClient64")]
public static extern void FTReportID(Int32 name);
[DllImport("FreeTrackClient64")]
public static extern string FTProvider();
public float Yaw = 0F;
public float Pitch = 0F;
public float Roll = 0F;
public float X = 0F;
public float Y = 0F;
public float Z = 0F;
public float RawYaw = 0F;
public float RawPitch = 0F;
public float RawRoll = 0F;
public float RawX = 0F;
public float RawY = 0F;
public float RawZ = 0F;
public float x1 = 0F;
public float y1 = 0F;
public float x2 = 0F;
public float y2 = 0F;
public float x3 = 0F;
public float y3 = 0F;
public float x4 = 0F;
public float y4 = 0F;
void Update()
{
FreeTrackClientDll.FreeTrackData FreeTrackData;
FreeTrackData = new FreeTrackClientDll.FreeTrackData();
if (!FreeTrackClientDll.FTGetData(ref FreeTrackData))
{
Debug.Log("FTGetData returned false. FreeTrack likely not working.");
return;
}
FreeTrackClientDll.FTGetData(ref FreeTrackData);
Yaw = FreeTrackData.Yaw;
Pitch = FreeTrackData.Pitch;
Roll = FreeTrackData.Roll;
X = FreeTrackData.X;
Y = FreeTrackData.Y;
Z = FreeTrackData.Z;
RawYaw = FreeTrackData.RawYaw;
RawPitch = FreeTrackData.RawPitch;
RawRoll = FreeTrackData.RawRoll;
RawX = FreeTrackData.RawX;
RawY = FreeTrackData.RawY;
RawZ = FreeTrackData.RawZ;
x1 = FreeTrackData.x1;
y1 = FreeTrackData.y1;
x2 = FreeTrackData.x2;
y2 = FreeTrackData.y2;
x3 = FreeTrackData.x3;
y3 = FreeTrackData.y3;
x4 = FreeTrackData.x4;
y4 = FreeTrackData.y4;
}
}
Here is a script that works quite nicely for smooth data, it is adapted from the same source. Use RAW input for unfiltered data.
using UnityEngine;
using System.Collections;
public class TranslateToCube : MonoBehaviour
{
public FreeTrackClientDll fTInput;
public bool useRAWData;
public Transform target;
public float positionScale = 0.001f;
public float positionLerpRate = 5;
public float rotationScale = 60.0f;
public float rotationLerpRate = 5;
private Vector3 startPos = Vector3.zero;
private Vector3 addedPos = Vector3.zero;
private Vector3 startEul = Vector3.zero;
private Vector3 addedEul = Vector3.zero;
void Start()
{
startPos = target.position;
startEul = target.eulerAngles;
}
void Update()
{
addedPos = Vector3.Lerp(addedPos, (new Vector3(fTInput.X, fTInput.Y, -fTInput.Z) * positionScale), positionLerpRate * Time.deltaTime);
addedEul = new Vector3(
Mathf.LerpAngle(addedEul.x, (useRAWData == true ? fTInput.RawPitch : fTInput.Pitch) * rotationScale, rotationLerpRate * Time.deltaTime),
Mathf.LerpAngle(addedEul.y, (useRAWData == true ? fTInput.RawYaw : fTInput.Yaw) * rotationScale, rotationLerpRate * Time.deltaTime),
Mathf.LerpAngle(addedEul.z, (useRAWData == true ? fTInput.RawRoll : fTInput.Roll) * rotationScale, rotationLerpRate * Time.deltaTime)
);
if (target)
{
target.position = startPos + addedPos;
target.eulerAngles = startEul + addedEul;
}
}
}
For those who are wondering where to get the FreeTrackClient64.dll : Go to http://www.facetracknoir.nl/ and download the free plugin-pack for FaceTrackNoIR. It will install the C:\Program Files (x86)\Abbequerque Inc\FaceTrackNoIR_v200\FreeTrackClient64.dll as mentioned in the solution.
Hi, I might be a little late, but I need help with your code.
I successfully integrated it into my project, but I don't understand the values I am receiving.
I am getting the values circled in red. Why am I not receiving the values listed at "Raw Input"?