|
@@ -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();
|
|
|
}
|
|
|
}
|
|
|
|