The face tracker can now offset face ids by a given value. This makes it possible to easily mix tracking input from multiple network sources.

This commit is contained in:
Emiliana 2020-02-16 15:58:47 +01:00
parent c2eb544096
commit 633293eb52
6 changed files with 64 additions and 64 deletions

View file

@ -6,12 +6,13 @@ namespace OpenSee {
public class OpenSeeShowPoints : MonoBehaviour {
public OpenSee openSee = null;
public int faceId = 0;
public bool show3DPoints = true;
public bool applyTranslation = false;
public bool applyRotation = false;
[Range(0, 1)]
public float minConfidence = 0.20f;
private OpenSee.OpenSeeData[] openSeeData;
private OpenSee.OpenSeeData openSeeData;
private GameObject[] gameObjects;
private GameObject centerBall;
private double updated = 0.0;
@ -36,21 +37,24 @@ public class OpenSeeShowPoints : MonoBehaviour {
void Update () {
if (!openSee)
return;
openSeeData = openSee.trackingData;
/*openSeeData = openSee.trackingData;
if (openSeeData == null || openSeeData.Length < 1)
return;*/
openSeeData = openSee.GetOpenSeeData(faceId);
if (openSeeData == null)
return;
if (openSeeData[0].time > updated) {
updated = openSeeData[0].time;
if (openSeeData.time > updated) {
updated = openSeeData.time;
} else {
return;
}
if (show3DPoints) {
centerBall.gameObject.SetActive(false);
for (int i = 0; i < 66; i++) {
if (openSeeData[0].got3DPoints && openSeeData[0].confidence[i] > minConfidence) {
if (openSeeData.got3DPoints && openSeeData.confidence[i] > minConfidence) {
Renderer renderer = gameObjects[i].GetComponent<Renderer>();
renderer.material.SetColor("_Color", Color.Lerp(Color.red, Color.green, openSeeData[0].confidence[i]));
Vector3 pt = openSeeData[0].points3D[i];
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;
} else {
@ -59,14 +63,14 @@ public class OpenSeeShowPoints : MonoBehaviour {
}
}
if (applyTranslation) {
Vector3 v = openSeeData[0].translation;
Vector3 v = openSeeData.translation;
v.x = -v.x;
v.z = -v.z;
transform.localPosition = v;
}
if (applyRotation) {
Quaternion offset = Quaternion.Euler(0f, 0f, -90f);
Quaternion convertedQuaternion = new Quaternion(-openSeeData[0].rawQuaternion.y, -openSeeData[0].rawQuaternion.x, openSeeData[0].rawQuaternion.z, openSeeData[0].rawQuaternion.w) * offset;
Quaternion convertedQuaternion = new Quaternion(-openSeeData.rawQuaternion.y, -openSeeData.rawQuaternion.x, openSeeData.rawQuaternion.z, openSeeData.rawQuaternion.w) * offset;
transform.localRotation = convertedQuaternion;
}
} else {
@ -77,8 +81,8 @@ public class OpenSeeShowPoints : MonoBehaviour {
float maxX = -1.0f;
float maxY = -1.0f;
for (int i = 0; i < 66; i++) {
float x = openSeeData[0].points[i].x;
float y = -openSeeData[0].points[i].y;
float x = openSeeData.points[i].x;
float y = -openSeeData.points[i].y;
if (minX > x) {
minX = x;
}
@ -102,9 +106,9 @@ public class OpenSeeShowPoints : MonoBehaviour {
for (int i = 0; i < 66; i++) {
Renderer renderer = gameObjects[i].GetComponent<Renderer>();
renderer.material.SetColor("_Color", Color.Lerp(Color.red, Color.green, openSeeData[0].confidence[i]));
float x = openSeeData[0].points[i].x;
float y = -openSeeData[0].points[i].y;
renderer.material.SetColor("_Color", Color.Lerp(Color.red, Color.green, openSeeData.confidence[i]));
float x = openSeeData.points[i].x;
float y = -openSeeData.points[i].y;
Vector3 position = new Vector3(x, y, 0.0f);
position = position - new Vector3(minX, minY, 0.0f);
position.x = position.x / (maxX - minX);