|
@@ -143,13 +143,14 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
|
|
|
|
private void Awake()
|
|
private void Awake()
|
|
{
|
|
{
|
|
- zedManagerLazy = new(new LoggingZEDManager(FindObjectOfType<ZEDManager>(), new DetectionFrameLogger()));
|
|
|
|
|
|
+ //zedManagerLazy = new(new LoggingZEDManager(FindObjectOfType<ZEDManager>(), new DetectionFrameLogger()));
|
|
|
|
+ zedManagerLazy = new(() => FindObjectOfType<ZEDManager>());
|
|
}
|
|
}
|
|
|
|
|
|
// Use this for initialization
|
|
// Use this for initialization
|
|
void Start()
|
|
void Start()
|
|
{
|
|
{
|
|
- ZedManager.OnObjectDetection += Visualize3DBoundingBoxes;
|
|
|
|
|
|
+ ZedManager.OnObjectDetection += ZedManager_OnObjectDetection;
|
|
ZedManager.OnZEDReady += OnZEDReady;
|
|
ZedManager.OnZEDReady += OnZEDReady;
|
|
|
|
|
|
if (ZedManager.EstimateInitialPosition == false && transformBoxToTouchFloor == true)
|
|
if (ZedManager.EstimateInitialPosition == false && transformBoxToTouchFloor == true)
|
|
@@ -159,6 +160,31 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void ZedManager_OnObjectDetection(DetectionFrame objFrame)
|
|
|
|
+ {
|
|
|
|
+ Visualize3DBoundingBoxes(objFrame);
|
|
|
|
+ UpdateMinMaxCoordinates(objFrame);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void UpdateMinMaxCoordinates(DetectionFrame objFrame)
|
|
|
|
+ {
|
|
|
|
+ List<DetectedObject> newobjects = objFrame.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
|
|
|
|
+ foreach (var detectedObject in newobjects)
|
|
|
|
+ {
|
|
|
|
+ Bounds objbounds = detectedObject.Get3DWorldBounds();
|
|
|
|
+ if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) { }
|
|
|
|
+ {
|
|
|
|
+ Vector3 obj_position = detectedObject.Get3DWorldPosition();
|
|
|
|
+ minX = Math.Min(minX, obj_position.x);
|
|
|
|
+ maxX = Math.Max(maxX, obj_position.x);
|
|
|
|
+ minY = Math.Min(minY, obj_position.y);
|
|
|
|
+ maxY = Math.Max(maxY, obj_position.y);
|
|
|
|
+ minZ = Math.Min(minZ, obj_position.z);
|
|
|
|
+ maxZ = Math.Max(maxZ, obj_position.z);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void OnZEDReady()
|
|
private void OnZEDReady()
|
|
{
|
|
{
|
|
if (startObjectDetectionAutomatically && !ZedManager.IsObjectDetectionRunning)
|
|
if (startObjectDetectionAutomatically && !ZedManager.IsObjectDetectionRunning)
|
|
@@ -167,6 +193,12 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ float maxX = 0.9971107f;
|
|
|
|
+ float minX = -0.7968294f;
|
|
|
|
+ float maxY = int.MinValue;
|
|
|
|
+ float minY = int.MaxValue;
|
|
|
|
+ float maxZ = 2.373606f;
|
|
|
|
+ float minZ = 0.4380694f;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Given a frame of object detections, positions a GameObject to represent every visible object
|
|
/// Given a frame of object detections, positions a GameObject to represent every visible object
|
|
@@ -181,19 +213,17 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
|
|
|
|
List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
|
|
List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
|
|
|
|
|
|
- if (newobjects.Any())
|
|
|
|
|
|
+ var ball = GameObject.Find("Sphere").GetComponent<Ball>();
|
|
|
|
+
|
|
|
|
+ if (ball.transform.position.x > -15 && ball.transform.position.x < 15 && newobjects.Any())
|
|
{
|
|
{
|
|
- if (newobjects.Count >= 2)
|
|
|
|
|
|
+ if (newobjects.Count >= 2 && !ball.IsInUse)
|
|
{
|
|
{
|
|
- var ball = GameObject.Find("Sphere").GetComponent<Ball>();
|
|
|
|
- if (!ball.IsInUse)
|
|
|
|
- {
|
|
|
|
- ball.Kickoff();
|
|
|
|
- }
|
|
|
|
|
|
+ ball.Kickoff();
|
|
}
|
|
}
|
|
|
|
|
|
int count = 1;
|
|
int count = 1;
|
|
- foreach (var dobj in newobjects.Take(2))
|
|
|
|
|
|
+ foreach (var dobj in newobjects.OrderByDescending(i => i.Get3DWorldPosition().x).Take(2))
|
|
{
|
|
{
|
|
GameObject bump = GameObject.Find($"Bump{count}");
|
|
GameObject bump = GameObject.Find($"Bump{count}");
|
|
Bounds objbounds = dobj.Get3DWorldBounds();
|
|
Bounds objbounds = dobj.Get3DWorldBounds();
|
|
@@ -210,22 +240,38 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
Vector3 obj_position = dobj.Get3DWorldPosition();
|
|
Vector3 obj_position = dobj.Get3DWorldPosition();
|
|
|
|
|
|
Debug.Log($"count: {count}; X: {obj_position.x}; Y: {obj_position.y}; Z: {obj_position.z};");
|
|
Debug.Log($"count: {count}; X: {obj_position.x}; Y: {obj_position.y}; Z: {obj_position.z};");
|
|
|
|
+ Debug.Log($"x: ({minX}|{maxX}), y: ({minY}|{maxY}), z: ({minZ}|{maxZ}), ");
|
|
|
|
|
|
if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
|
|
if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
|
|
{
|
|
{
|
|
bbox.transform.position = obj_position;
|
|
bbox.transform.position = obj_position;
|
|
- if (obj_position.z > 3 && obj_position.z < 4)
|
|
|
|
- {
|
|
|
|
- var scale = obj_position.z - 3;
|
|
|
|
- var newZ = scale * 8 - 4;
|
|
|
|
- bump.transform.position = new Vector3(bump.transform.position.x, bump.transform.position.y, newZ);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
if (floorBBoxPosition)
|
|
if (floorBBoxPosition)
|
|
{
|
|
{
|
|
bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
|
|
bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var x = bbox.transform.position.x;
|
|
|
|
+
|
|
|
|
+ var totalDistance = maxX - minX;
|
|
|
|
+ var distanceFromStart = x - minX;
|
|
|
|
+ var ratio = distanceFromStart / totalDistance;
|
|
|
|
+ var newX = -12 + ratio * 24;
|
|
|
|
+
|
|
|
|
+ var z = bbox.transform.position.z;
|
|
|
|
+
|
|
|
|
+ totalDistance = maxZ - minZ;
|
|
|
|
+ distanceFromStart = z - minZ;
|
|
|
|
+ ratio = distanceFromStart / totalDistance;
|
|
|
|
+ var newZ = -6 + ratio * 12;
|
|
|
|
+
|
|
|
|
+ bbox.transform.position = new Vector3(newX, 0, newZ);
|
|
bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
|
|
bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
|
|
|
|
+
|
|
|
|
+ if (bbox.transform.position.z > -5 && bbox.transform.position.z < 5)
|
|
|
|
+ {
|
|
|
|
+ bump.transform.position = new Vector3(bump.transform.position.x, bump.transform.position.y, bbox.transform.position.z);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//Transform the box if desired.
|
|
//Transform the box if desired.
|
|
@@ -274,7 +320,6 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- var ball = GameObject.Find("Sphere").GetComponent<Ball>();
|
|
|
|
ball.Recenter();
|
|
ball.Recenter();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -395,7 +440,7 @@ public class ZED3DObjectVisualizer : MonoBehaviour
|
|
{
|
|
{
|
|
if (ZedManager != null)
|
|
if (ZedManager != null)
|
|
{
|
|
{
|
|
- ZedManager.OnObjectDetection -= Visualize3DBoundingBoxes;
|
|
|
|
|
|
+ ZedManager.OnObjectDetection -= ZedManager_OnObjectDetection;
|
|
ZedManager.OnZEDReady -= OnZEDReady;
|
|
ZedManager.OnZEDReady -= OnZEDReady;
|
|
}
|
|
}
|
|
}
|
|
}
|