This adds the gaze tracker.
This commit is contained in:
parent
2d35cc2aaf
commit
0332f9cb93
6 changed files with 329 additions and 70 deletions
|
|
@ -15,7 +15,7 @@ public class OpenSee : MonoBehaviour {
|
|||
[Tooltip("This is the port the server will listen for tracking packets on")]
|
||||
public int listenPort = 11573;
|
||||
|
||||
private const int nPoints = 66;
|
||||
private const int nPoints = 68;
|
||||
private const int packetFrameSize = 8 + 4 + 2 * 4 + 2 * 4 + 1 + 4 + 3 * 4 + 3 * 4 + 4 * 4 + 4 * 68 + 4 * 2 * 68 + 4 * 3 * 70;
|
||||
|
||||
[Header("Tracking data")]
|
||||
|
|
@ -36,6 +36,10 @@ public class OpenSee : MonoBehaviour {
|
|||
public float rightEyeOpen;
|
||||
[Tooltip("This field tells you how likely it is that the left eye is open.")]
|
||||
public float leftEyeOpen;
|
||||
[Tooltip("This field tells you how likely it is that the right eye is open.")]
|
||||
public Quaternion rightGaze;
|
||||
[Tooltip("This field tells you how likely it is that the left eye is open.")]
|
||||
public Quaternion leftGaze;
|
||||
[Tooltip("This field tells you if 3D points have been successfully estimated from the 2D points. If this is false, do not rely on pose or 3D data.")]
|
||||
public bool got3DPoints;
|
||||
[Tooltip("This field contains the error for fitting the original 3D points. It shouldn't matter much, but it it is very high, something is probably wrong")]
|
||||
|
|
@ -58,7 +62,12 @@ public class OpenSee : MonoBehaviour {
|
|||
public OpenSeeData() {
|
||||
confidence = new float[nPoints];
|
||||
points = new Vector2[nPoints];
|
||||
points3D = new Vector3[nPoints];
|
||||
points3D = new Vector3[nPoints + 2];
|
||||
}
|
||||
|
||||
private Vector3 swapX(Vector3 v) {
|
||||
v.x = -v.x;
|
||||
return v;
|
||||
}
|
||||
|
||||
private float readFloat(byte[] b, ref int o) {
|
||||
|
|
@ -120,22 +129,16 @@ public class OpenSee : MonoBehaviour {
|
|||
confidence[i] = readFloat(b, ref o);
|
||||
}
|
||||
|
||||
// Gaze tracker results are still bad, ignore them
|
||||
readFloat(b, ref o); readFloat(b, ref o);
|
||||
|
||||
for (int i = 0; i < nPoints; i++) {
|
||||
points[i] = readVector2(b, ref o);
|
||||
}
|
||||
|
||||
// Gaze tracker results are still bad, ignore them
|
||||
readVector2(b, ref o); readVector2(b, ref o);
|
||||
|
||||
for (int i = 0; i < nPoints; i++) {
|
||||
for (int i = 0; i < nPoints + 2; i++) {
|
||||
points3D[i] = readVector3(b, ref o);
|
||||
}
|
||||
|
||||
// Gaze tracker results are still bad, ignore them
|
||||
readVector3(b, ref o); readVector3(b, ref o); readVector3(b, ref o); readVector3(b, ref o);
|
||||
|
||||
rightGaze = Quaternion.LookRotation(swapX(points3D[66]) - swapX(points3D[68])) * Quaternion.AngleAxis(180, Vector3.right) * Quaternion.AngleAxis(180, Vector3.forward);
|
||||
leftGaze = Quaternion.LookRotation(swapX(points3D[67]) - swapX(points3D[69])) * Quaternion.AngleAxis(180, Vector3.right) * Quaternion.AngleAxis(180, Vector3.forward);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,19 @@ public class OpenSeeShowPoints : MonoBehaviour {
|
|||
if (openSee == null) {
|
||||
openSee = GetComponent<OpenSee>();
|
||||
}
|
||||
gameObjects = new GameObject[68];
|
||||
for (int i = 0; i < 68; i++) {
|
||||
gameObjects = new GameObject[70];
|
||||
for (int i = 0; i < 70; i++) {
|
||||
gameObjects[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
gameObjects[i].name = "Point " + (i + 1);
|
||||
gameObjects[i].transform.SetParent(transform);
|
||||
gameObjects[i].transform.localScale = new Vector3(0.025f, 0.025f, 0.025f);
|
||||
if (i >= 68) {
|
||||
GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
||||
cylinder.transform.SetParent(gameObjects[i].transform);
|
||||
cylinder.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
|
||||
cylinder.transform.localPosition = new Vector3(0f, 0f, -4f);
|
||||
cylinder.transform.localScale = new Vector3(1f, 4f, 1f);
|
||||
}
|
||||
}
|
||||
centerBall = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
centerBall.name = "Center";
|
||||
|
|
@ -50,13 +57,20 @@ public class OpenSeeShowPoints : MonoBehaviour {
|
|||
}
|
||||
if (show3DPoints) {
|
||||
centerBall.gameObject.SetActive(false);
|
||||
for (int i = 0; i < 66; i++) {
|
||||
if (openSeeData.got3DPoints && openSeeData.confidence[i] > minConfidence) {
|
||||
for (int i = 0; i < 70; i++) {
|
||||
if (openSeeData.got3DPoints && (i >= 68 || openSeeData.confidence[i] > minConfidence)) {
|
||||
Renderer renderer = gameObjects[i].GetComponent<Renderer>();
|
||||
renderer.material.SetColor("_Color", Color.Lerp(Color.red, Color.green, openSeeData.confidence[i]));
|
||||
Vector3 pt = openSeeData.points3D[i];
|
||||
pt.x = -pt.x;
|
||||
gameObjects[i].transform.localPosition = pt;
|
||||
if (i < 68)
|
||||
renderer.material.SetColor("_Color", Color.Lerp(Color.red, Color.green, openSeeData.confidence[i]));
|
||||
else {
|
||||
if (i == 68)
|
||||
gameObjects[i].transform.localRotation = openSeeData.rightGaze;
|
||||
else
|
||||
gameObjects[i].transform.localRotation = openSeeData.leftGaze;
|
||||
}
|
||||
} else {
|
||||
Renderer renderer = gameObjects[i].GetComponent<Renderer>();
|
||||
renderer.material.SetColor("_Color", Color.cyan);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue