|
@@ -1,5 +1,6 @@
|
|
using Assets.Logging;
|
|
using Assets.Logging;
|
|
using Assets.StreetLight.Poco;
|
|
using Assets.StreetLight.Poco;
|
|
|
|
+using Assets.StreetLight.Scripts;
|
|
using Assets.ZED.SDK.Helpers.Scripts;
|
|
using Assets.ZED.SDK.Helpers.Scripts;
|
|
using System;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections;
|
|
@@ -7,125 +8,128 @@ using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
|
|
|
|
-public class PersonVisualizer : MonoBehaviour
|
|
|
|
|
|
+namespace Assets.StreetLight
|
|
{
|
|
{
|
|
- PersonManager PersonManager => personManagerLazy.Value;
|
|
|
|
- Lazy<PersonManager> personManagerLazy;
|
|
|
|
-
|
|
|
|
- public GameObject boundingBoxPrefab;
|
|
|
|
-
|
|
|
|
- IDictionary<int, GameObject> markers = new Dictionary<int, GameObject>();
|
|
|
|
-
|
|
|
|
- private void Awake()
|
|
|
|
|
|
+ public class PersonVisualizer : MonoBehaviour
|
|
{
|
|
{
|
|
- personManagerLazy = new Lazy<PersonManager>(FindObjectOfType<PersonManager>);
|
|
|
|
- }
|
|
|
|
|
|
+ PersonManager PersonManager => personManagerLazy.Value;
|
|
|
|
+ Lazy<PersonManager> personManagerLazy;
|
|
|
|
|
|
- GameObject[] spheres;
|
|
|
|
|
|
+ public GameObject boundingBoxPrefab;
|
|
|
|
|
|
- void Start()
|
|
|
|
- {
|
|
|
|
- spheres = new GameObject[] { GameObject.CreatePrimitive(PrimitiveType.Sphere), GameObject.CreatePrimitive(PrimitiveType.Sphere) };
|
|
|
|
- }
|
|
|
|
|
|
+ IDictionary<int, GameObject> markers = new Dictionary<int, GameObject>();
|
|
|
|
|
|
- void Update()
|
|
|
|
- {
|
|
|
|
- int count = 0;
|
|
|
|
- foreach (var person in PersonManager.Persons.OrderBy(p => p.Id))
|
|
|
|
|
|
+ private void Awake()
|
|
{
|
|
{
|
|
- GameObject sphere = spheres[count];
|
|
|
|
- sphere.transform.position = new Vector3(person.UnityPosition.x, person.UnityPosition.y, person.UnityPosition.z);
|
|
|
|
-
|
|
|
|
- //var camera = Camera.main;
|
|
|
|
- //Vector3[] frustumCorners = new Vector3[4];
|
|
|
|
- //camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.transform.position.y, Camera.MonoOrStereoscopicEye.Mono, frustumCorners);
|
|
|
|
-
|
|
|
|
- //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
- //sphere.transform.position = new Vector3(0, 0, 0);
|
|
|
|
- //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
- //sphere.transform.position = new Vector3(0, 0, Camera.main.rect.width);
|
|
|
|
- //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
- //sphere.transform.position = new Vector3(Camera.main.rect.height, 0, 0);
|
|
|
|
- //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
- //sphere.transform.position = new Vector3(Camera.main.rect.height, 0, Camera.main.rect.width);
|
|
|
|
- count++;
|
|
|
|
|
|
+ personManagerLazy = new Lazy<PersonManager>(FindObjectOfType<PersonManager>);
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- float GroundPositionToSceneCoordinate(float minValue, float actualValue)
|
|
|
|
- {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- private void ReturnBoxToPool(int id, RectTransform bbox)
|
|
|
|
- {
|
|
|
|
- bbox.gameObject.SetActive(false);
|
|
|
|
- bbox.name = "Unused";
|
|
|
|
-
|
|
|
|
- bboxPool.Push(bbox.gameObject);
|
|
|
|
|
|
+ GameObject[] spheres;
|
|
|
|
|
|
- if (liveBBoxes.ContainsKey(id))
|
|
|
|
|
|
+ void Start()
|
|
{
|
|
{
|
|
- liveBBoxes.Remove(id);
|
|
|
|
|
|
+ spheres = new GameObject[] { GameObject.CreatePrimitive(PrimitiveType.Sphere), GameObject.CreatePrimitive(PrimitiveType.Sphere) };
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+
|
|
|
|
+ void Update()
|
|
{
|
|
{
|
|
- Debug.LogError("Tried to remove object ID " + id + " from active bboxes, but it wasn't in the dictionary.");
|
|
|
|
|
|
+ int count = 0;
|
|
|
|
+ foreach (var person in PersonManager.Persons.OrderBy(p => p.Id))
|
|
|
|
+ {
|
|
|
|
+ GameObject sphere = spheres[count];
|
|
|
|
+ var unityPosition = PersonManager.PositionCalculator.CalculateUnityPosition(person);
|
|
|
|
+ sphere.transform.position = new Vector3(unityPosition.x, unityPosition.y, unityPosition.z);
|
|
|
|
+
|
|
|
|
+ //var camera = Camera.main;
|
|
|
|
+ //Vector3[] frustumCorners = new Vector3[4];
|
|
|
|
+ //camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.transform.position.y, Camera.MonoOrStereoscopicEye.Mono, frustumCorners);
|
|
|
|
+
|
|
|
|
+ //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
+ //sphere.transform.position = new Vector3(0, 0, 0);
|
|
|
|
+ //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
+ //sphere.transform.position = new Vector3(0, 0, Camera.main.rect.width);
|
|
|
|
+ //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
+ //sphere.transform.position = new Vector3(Camera.main.rect.height, 0, 0);
|
|
|
|
+ //sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
+ //sphere.transform.position = new Vector3(Camera.main.rect.height, 0, Camera.main.rect.width);
|
|
|
|
+ count++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- private Dictionary<int, RectTransform> liveBBoxes = new Dictionary<int, RectTransform>();
|
|
|
|
- private Dictionary<int, Color> idColorDict = new Dictionary<int, Color>();
|
|
|
|
-
|
|
|
|
- private Stack<GameObject> bboxPool = new Stack<GameObject>();
|
|
|
|
|
|
+ float GroundPositionToSceneCoordinate(float minValue, float actualValue)
|
|
|
|
+ {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Returs the RectTransform within the GameObject (instantiated from boundingBoxPrefab) that represents the provided DetectedObject.
|
|
|
|
- /// If none exists, it retrieves one from the pool (or instantiates a new one if none is available) and
|
|
|
|
- /// sets it up with the proper ID and colors.
|
|
|
|
- /// </summary>
|
|
|
|
- private RectTransform GetBBoxForObject(Person dobj)
|
|
|
|
- {
|
|
|
|
- if (!liveBBoxes.ContainsKey(dobj.Id))
|
|
|
|
|
|
+ private void ReturnBoxToPool(int id, RectTransform bbox)
|
|
{
|
|
{
|
|
- GameObject newbox = GetAvailableBBox();
|
|
|
|
- //newbox.transform.SetParent(canvas.transform, false);
|
|
|
|
- newbox.name = "Object #" + dobj.Id;
|
|
|
|
|
|
+ bbox.gameObject.SetActive(false);
|
|
|
|
+ bbox.name = "Unused";
|
|
|
|
+
|
|
|
|
+ bboxPool.Push(bbox.gameObject);
|
|
|
|
|
|
- Color col;
|
|
|
|
- if (idColorDict.ContainsKey(dobj.Id))
|
|
|
|
|
|
+ if (liveBBoxes.ContainsKey(id))
|
|
{
|
|
{
|
|
- col = idColorDict[dobj.Id];
|
|
|
|
|
|
+ liveBBoxes.Remove(id);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- col = GetNextColor();
|
|
|
|
- idColorDict.Add(dobj.Id, col);
|
|
|
|
|
|
+ Debug.LogError("Tried to remove object ID " + id + " from active bboxes, but it wasn't in the dictionary.");
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- BBox2DHandler boxhandler = newbox.GetComponent<BBox2DHandler>();
|
|
|
|
- if (boxhandler)
|
|
|
|
- {
|
|
|
|
- boxhandler.SetColor(col);
|
|
|
|
- boxhandler.SetID(dobj.Id);
|
|
|
|
- }
|
|
|
|
|
|
+ private Dictionary<int, RectTransform> liveBBoxes = new Dictionary<int, RectTransform>();
|
|
|
|
+ private Dictionary<int, Color> idColorDict = new Dictionary<int, Color>();
|
|
|
|
|
|
|
|
+ private Stack<GameObject> bboxPool = new Stack<GameObject>();
|
|
|
|
|
|
- RectTransform newrecttrans = newbox.GetComponent<RectTransform>();
|
|
|
|
- if (!newrecttrans)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Returs the RectTransform within the GameObject (instantiated from boundingBoxPrefab) that represents the provided DetectedObject.
|
|
|
|
+ /// If none exists, it retrieves one from the pool (or instantiates a new one if none is available) and
|
|
|
|
+ /// sets it up with the proper ID and colors.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private RectTransform GetBBoxForObject(Person dobj)
|
|
|
|
+ {
|
|
|
|
+ if (!liveBBoxes.ContainsKey(dobj.Id))
|
|
{
|
|
{
|
|
- Debug.LogError("BBox prefab needs a RectTransform in the root object.");
|
|
|
|
- return null;
|
|
|
|
|
|
+ GameObject newbox = GetAvailableBBox();
|
|
|
|
+ //newbox.transform.SetParent(canvas.transform, false);
|
|
|
|
+ newbox.name = "Object #" + dobj.Id;
|
|
|
|
+
|
|
|
|
+ Color col;
|
|
|
|
+ if (idColorDict.ContainsKey(dobj.Id))
|
|
|
|
+ {
|
|
|
|
+ col = idColorDict[dobj.Id];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ col = GetNextColor();
|
|
|
|
+ idColorDict.Add(dobj.Id, col);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BBox2DHandler boxhandler = newbox.GetComponent<BBox2DHandler>();
|
|
|
|
+ if (boxhandler)
|
|
|
|
+ {
|
|
|
|
+ boxhandler.SetColor(col);
|
|
|
|
+ boxhandler.SetID(dobj.Id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ RectTransform newrecttrans = newbox.GetComponent<RectTransform>();
|
|
|
|
+ if (!newrecttrans)
|
|
|
|
+ {
|
|
|
|
+ Debug.LogError("BBox prefab needs a RectTransform in the root object.");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ liveBBoxes[dobj.Id] = newrecttrans;
|
|
|
|
+ return newrecttrans;
|
|
}
|
|
}
|
|
|
|
+ else return liveBBoxes[dobj.Id];
|
|
|
|
|
|
- liveBBoxes[dobj.Id] = newrecttrans;
|
|
|
|
- return newrecttrans;
|
|
|
|
}
|
|
}
|
|
- else return liveBBoxes[dobj.Id];
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
|
|
- public List<Color> boxColors = new List<Color>()
|
|
|
|
|
|
+ public List<Color> boxColors = new List<Color>()
|
|
{
|
|
{
|
|
new Color(.231f, .909f, .69f, 1),
|
|
new Color(.231f, .909f, .69f, 1),
|
|
new Color(.098f, .686f, .816f, 1),
|
|
new Color(.098f, .686f, .816f, 1),
|
|
@@ -134,45 +138,46 @@ public class PersonVisualizer : MonoBehaviour
|
|
new Color(.989f, .388f, .419f, 1)
|
|
new Color(.989f, .388f, .419f, 1)
|
|
};
|
|
};
|
|
|
|
|
|
- private int nextColorIndex = 0;
|
|
|
|
|
|
+ private int nextColorIndex = 0;
|
|
|
|
|
|
- private Color GetNextColor()
|
|
|
|
- {
|
|
|
|
- if (boxColors.Count == 0)
|
|
|
|
|
|
+ private Color GetNextColor()
|
|
{
|
|
{
|
|
- return new Color(.043f, .808f, .435f, 1);
|
|
|
|
- }
|
|
|
|
|
|
+ if (boxColors.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ return new Color(.043f, .808f, .435f, 1);
|
|
|
|
+ }
|
|
|
|
|
|
- if (nextColorIndex >= boxColors.Count)
|
|
|
|
- {
|
|
|
|
- nextColorIndex = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ if (nextColorIndex >= boxColors.Count)
|
|
|
|
+ {
|
|
|
|
+ nextColorIndex = 0;
|
|
|
|
+ }
|
|
|
|
|
|
- Color returncol = boxColors[nextColorIndex];
|
|
|
|
|
|
+ Color returncol = boxColors[nextColorIndex];
|
|
|
|
|
|
- nextColorIndex++;
|
|
|
|
|
|
+ nextColorIndex++;
|
|
|
|
|
|
|
|
|
|
- return returncol;
|
|
|
|
- }
|
|
|
|
|
|
+ return returncol;
|
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets an available GameObject (instantiated from boundingBoxPrefab) from the pool,
|
|
|
|
- /// or instantiates a new one if none are available.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- private GameObject GetAvailableBBox()
|
|
|
|
- {
|
|
|
|
- if (bboxPool.Count == 0)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets an available GameObject (instantiated from boundingBoxPrefab) from the pool,
|
|
|
|
+ /// or instantiates a new one if none are available.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ private GameObject GetAvailableBBox()
|
|
{
|
|
{
|
|
- GameObject newbbox = Instantiate(boundingBoxPrefab);
|
|
|
|
- newbbox.transform.SetParent(transform, false);
|
|
|
|
- bboxPool.Push(newbbox);
|
|
|
|
- }
|
|
|
|
|
|
+ if (bboxPool.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ GameObject newbbox = Instantiate(boundingBoxPrefab);
|
|
|
|
+ newbbox.transform.SetParent(transform, false);
|
|
|
|
+ bboxPool.Push(newbbox);
|
|
|
|
+ }
|
|
|
|
|
|
- GameObject bbox = bboxPool.Pop();
|
|
|
|
- bbox.SetActive(true);
|
|
|
|
|
|
+ GameObject bbox = bboxPool.Pop();
|
|
|
|
+ bbox.SetActive(true);
|
|
|
|
|
|
- return bbox;
|
|
|
|
|
|
+ return bbox;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|