Browse Source

Remove pong logic from 3dObjectVisualizer

Nick Steyer 1 year ago
parent
commit
474597c8a2

File diff suppressed because it is too large
+ 0 - 0
Assembly-CSharp-Editor.csproj


File diff suppressed because it is too large
+ 0 - 0
Assembly-CSharp.csproj


+ 43 - 123
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -5,6 +5,7 @@ using System.Linq;
 using Assets.Logging;
 using Assets.ZED.SDK.Helpers.Scripts;
 using UnityEngine;
+using UnityEngine.UIElements;
 
 /// <summary>
 /// For the ZED 3D Object Detection sample.
@@ -146,7 +147,6 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         zedManagerLazy = new(new LoggingZEDManager(FindObjectOfType<ZEDManager>(), new DetectionFrameLogger()));
     }
 
-    // Use this for initialization
     void Start()
     {
         ZedManager.OnObjectDetection += ZedManager_OnObjectDetection;
@@ -162,26 +162,6 @@ 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()
@@ -192,12 +172,6 @@ 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>
     /// Given a frame of object detections, positions a GameObject to represent every visible object
@@ -211,115 +185,58 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         List<int> activeids = liveBBoxes.Keys.ToList();
 
         List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
+        foreach (DetectedObject dobj in newobjects)
+        {
+            Bounds objbounds = dobj.Get3DWorldBounds();
+            //Make sure the object is big enough to count. We filter out very small boxes.
+            if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) continue;
 
-        var ball = GameObject.Find("Sphere").GetComponent<Ball>();
+            //Remove the ID from the list we'll use to clear no-longer-visible boxes.
+            if (activeids.Contains(dobj.id)) activeids.Remove(dobj.id);
 
-        if (ball.transform.position.x > -15 && ball.transform.position.x < 15 && newobjects.Any())
-        {
-            if (newobjects.Count >= 2 && !ball.IsInUse)
+            //Get the box and update its distance value.
+            GameObject bbox = GetBBoxForObject(dobj);
+
+            //Move the box into position.
+            Vector3 obj_position = dobj.Get3DWorldPosition();
+
+            if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
             {
-                ball.Kickoff();
+                bbox.transform.position = obj_position;
+                if (floorBBoxPosition)
+                {
+                    bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
+                }
+
+                bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
             }
 
-            int count = 1;
-            foreach (var dobj in newobjects.OrderByDescending(i => i.Get3DWorldPosition().x).Take(2))
+            //Transform the box if desired.
+            if (transformBoxScale)
             {
-                GameObject bump = GameObject.Find($"Bump{count}");
-                Bounds objbounds = dobj.Get3DWorldBounds();
-                //Make sure the object is big enough to count. We filter out very small boxes.
-                if (objbounds.size.x < minimumWidthToDisplay || objbounds.size == Vector3.zero) { }
+                //We'll scale the object assuming that it's mesh is the default Unity cube, or something sized equally.
+                if (transformBoxToTouchFloor)
                 {
-                    //Remove the ID from the list we'll use to clear no-longer-visible boxes.
-                    if (activeids.Contains(dobj.id)) activeids.Remove(dobj.id);
-
-                    //Get the box and update its distance value.
-                    GameObject bbox = GetBBoxForObject(dobj);
-
-                    //Move the box into position.
-                    Vector3 obj_position = dobj.Get3DWorldPosition();
-
-                    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))
-                    {
-                        bbox.transform.position = obj_position;
-
-                        if (floorBBoxPosition)
-                        {
-                            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.
-
-                        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.
-                    if (transformBoxScale)
-                    {
-                        //We'll scale the object assuming that it's mesh is the default Unity cube, or something sized equally.
-                        if (transformBoxToTouchFloor)
-                        {
-                            Vector3 startscale = objbounds.size;
-                            float distfromfloor = bbox.transform.position.y - (objbounds.size.y / 2f);
-                            bbox.transform.localScale = new Vector3(objbounds.size.x, objbounds.size.y + distfromfloor, objbounds.size.z);
-                            Vector3 newpos = bbox.transform.position;
-                            newpos.y -= (distfromfloor / 2f);
-
-                            bbox.transform.position = newpos;
-
-                        }
-                        else
-                        {
-                            bbox.transform.localScale = objbounds.size;
-                        }
-                    }
-
-                    //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
-                    BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
-                    if (boxhandler)
-                    {
-                        float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
-                        boxhandler.SetDistance(disttobox);
-
-                        boxhandler.UpdateBoxUVScales();
-                        boxhandler.UpdateLabelScaleAndPosition();
-                    }
-
-                    //DrawDebugBox(dobj);
-                }
+                    Vector3 startscale = objbounds.size;
+                    float distfromfloor = bbox.transform.position.y - (objbounds.size.y / 2f);
+                    bbox.transform.localScale = new Vector3(objbounds.size.x, objbounds.size.y + distfromfloor, objbounds.size.z);
+                    Vector3 newpos = bbox.transform.position;
+                    newpos.y -= (distfromfloor / 2f);
 
-                //Remove boxes for objects that the ZED can no longer see.
-                foreach (int id in activeids)
+                    bbox.transform.position = newpos;
+                }
+                else
                 {
-                    ReturnBoxToPool(id, liveBBoxes[id]);
+                    bbox.transform.localScale = objbounds.size;
                 }
+            }
 
             //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
             BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
             if (boxhandler)
             {
                 var position = dobj.Get3DWorldPosition();
-                float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, position);
+                float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
                 boxhandler.SetDistance(disttobox);
                 boxhandler.SetX(position.x);
                 boxhandler.SetY(position.y);
@@ -327,13 +244,16 @@ public class ZED3DObjectVisualizer : MonoBehaviour
 
                 boxhandler.UpdateBoxUVScales();
                 boxhandler.UpdateLabelScaleAndPosition();
-                count++;
                 Debug.Log($"Frame {dframe.frameCountAtDetection}, X: {position.x}, Y: {position.y}, Z: {position.z}");
             }
+
+            //DrawDebugBox(dobj);
         }
-        else
+
+        //Remove boxes for objects that the ZED can no longer see.
+        foreach (int id in activeids)
         {
-            ball.Recenter();
+            ReturnBoxToPool(id, liveBBoxes[id]);
         }
     }
 

Some files were not shown because too many files changed in this diff