Ver código fonte

Implement reset mechanism and set build settings

Nick Steyer 2 anos atrás
pai
commit
9d478d0db1

+ 12 - 5
Assets/Ball.cs

@@ -5,24 +5,31 @@ using UnityEngine;
 
 public class Ball : MonoBehaviour
 {
+    public bool IsInUse { get; private set; }
     public float speed = 5f;
 
     // Start is called before the first frame update
     void Start()
     {
-        //Thread.Sleep(5000);
-        //float sx = Random.Range(0, 2) == 0 ? -1 : 1;
-        //float sz = Random.Range(0, 2) == 0 ? -1 : 1;
+    }
+
+    public void Recenter()
+    {
+        var component = GetComponent<Rigidbody>();
+        component.velocity = Vector3.zero;
+        component.transform.position = Vector3.zero;
 
-        //GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
+        IsInUse = false;
     }
 
-    public void Init()
+    public void Kickoff()
     {
         float sx = Random.Range(0, 2) == 0 ? -1 : 1;
         float sz = Random.Range(0, 2) == 0 ? -1 : 1;
 
         GetComponent<Rigidbody>().velocity = new Vector3(speed * sx, 0f, speed * sz);
+
+        IsInUse = true;
     }
 
     // Update is called once per frame

+ 8 - 0
Assets/StreamingAssets.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6e366189f88f00540bd2374d78c104bc
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 75 - 61
Assets/ZED/Examples/Object Detection/Scripts/ZED3DObjectVisualizer.cs

@@ -160,9 +160,6 @@ public class ZED3DObjectVisualizer : MonoBehaviour
         {
             zedManager.StartObjectDetection();
         }
-
-        var ball = (Ball)GameObject.Find("Sphere").GetComponent<Ball>();
-        ball.Init();
     }
 
 
@@ -179,84 +176,101 @@ public class ZED3DObjectVisualizer : MonoBehaviour
 
         List<DetectedObject> newobjects = dframe.GetFilteredObjectList(showONTracked, showSEARCHINGTracked, showOFFTracked);
 
-        int count = 1;
-        foreach (var dobj in newobjects.Take(2))
+        if (newobjects.Any())
         {
-            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) { }
+            if (newobjects.Count >= 2)
+            {
+                var ball = GameObject.Find("Sphere").GetComponent<Ball>();
+                if (!ball.IsInUse)
+                {
+                    ball.Kickoff();
+                }
+            }
+
+            int count = 1;
+            foreach (var dobj in newobjects.Take(2))
             {
-                //Remove the ID from the list we'll use to clear no-longer-visible boxes.
-                if (activeids.Contains(dobj.id)) activeids.Remove(dobj.id);
+                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) { }
+                {
+                    //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);
+                    //Get the box and update its distance value.
+                    GameObject bbox = GetBBoxForObject(dobj);
 
-                //Move the box into position.
-                Vector3 obj_position = dobj.Get3DWorldPosition();
+                    //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($"count: {count}; X: {obj_position.x}; Y: {obj_position.y}; Z: {obj_position.z};");
 
-                if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
-                {
-                    bbox.transform.position = obj_position;
-                    if (obj_position.z > 3 && obj_position.z < 4)
+                    if (!ZEDSupportFunctions.IsVector3NaN(obj_position))
                     {
-                        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);
+                        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)
+                        {
+                            bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
+                        }
+
+                        bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
                     }
-                    if (floorBBoxPosition)
+
+                    //Transform the box if desired.
+                    if (transformBoxScale)
                     {
-                        bbox.transform.position = new Vector3(bbox.transform.position.x, 0, bbox.transform.position.z);
+                        //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;
+                        }
                     }
 
-                    bbox.transform.rotation = dobj.Get3DWorldRotation(boxesFaceCamera); //Rotate them.
-                }
-
-                //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)
+                    //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
+                    BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
+                    if (boxhandler)
                     {
-                        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);
+                        float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
+                        boxhandler.SetDistance(disttobox);
 
-                        bbox.transform.position = newpos;
-
-                    }
-                    else
-                    {
-                        bbox.transform.localScale = objbounds.size;
+                        boxhandler.UpdateBoxUVScales();
+                        boxhandler.UpdateLabelScaleAndPosition();
                     }
+
+                    //DrawDebugBox(dobj);
                 }
 
-                //Now that we've adjusted position, tell the handler on the prefab to adjust distance display..
-                BBox3DHandler boxhandler = bbox.GetComponent<BBox3DHandler>();
-                if (boxhandler)
+                //Remove boxes for objects that the ZED can no longer see.
+                foreach (int id in activeids)
                 {
-                    float disttobox = Vector3.Distance(dobj.detectingZEDManager.GetLeftCameraTransform().position, dobj.Get3DWorldPosition());
-                    boxhandler.SetDistance(disttobox);
-
-                    boxhandler.UpdateBoxUVScales();
-                    boxhandler.UpdateLabelScaleAndPosition();
+                    ReturnBoxToPool(id, liveBBoxes[id]);
                 }
 
-                //DrawDebugBox(dobj);
-            }
-
-            //Remove boxes for objects that the ZED can no longer see.
-            foreach (int id in activeids)
-            {
-                ReturnBoxToPool(id, liveBBoxes[id]);
+                count++;
             }
-
-            count++;
+        }
+        else
+        {
+            var ball = GameObject.Find("Sphere").GetComponent<Ball>();
+            ball.Recenter();
         }
     }
 

+ 4 - 1
ProjectSettings/EditorBuildSettings.asset

@@ -4,5 +4,8 @@
 EditorBuildSettings:
   m_ObjectHideFlags: 0
   serializedVersion: 2
-  m_Scenes: []
+  m_Scenes:
+  - enabled: 1
+    path: Assets/Scenes/BoundingBoxes.unity
+    guid: 2caa6160a09e21c43b6d6206da9a152b
   m_configObjects: {}