protected virtual void PlaneUpdatedHandler(BoundedPlane plane) { if (m_PlanePrefab) { CreateOrUpdateGameObject(plane); } }
protected void OnPlaneRemoved(BoundedPlane plane) { if (planeRemoved != null) { planeRemoved(plane); } }
private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp) { var extents = (tp.ExtentX != bp.extents.x || tp.ExtentZ != bp.extents.y); var rotation = tp.Rotation != bp.rotation; var position = tp.Position != bp.center; return(extents || rotation || position); }
private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp) { var extents = (!FloatCompare(tp.ExtentX, bp.extents.x) || !FloatCompare(tp.ExtentZ, bp.extents.y)); var rotation = tp.Rotation != bp.rotation; var position = tp.Position != bp.center; return(extents || rotation || position); }
void ARInterface_PlaneAdded(UnityARInterface.BoundedPlane obj) { _lastHeight = obj.center.y; IndoorMappingDemo.ApplicationUIManager.Instance.OnStateChanged(IndoorMappingDemo.ApplicationState.AR_Calibration); ARInterface.planeAdded -= ARInterface_PlaneAdded; Debug.Log("Plane Detected"); ARInterface.planeAdded -= ARInterface_PlaneAdded; }
private bool PlaneUpdated(TrackedPlane tp, BoundedPlane bp) { var tpExtents = new Vector2(tp.ExtentX, tp.ExtentZ); var extents = Vector2.Distance(tpExtents, bp.extents) > 0.005f; var rotation = tp.Rotation != bp.rotation; var position = Vector2.Distance(tp.Position, bp.center) > 0.005f; return(extents || rotation || position); }
private bool PlaneUpdated(DetectedPlane dp, BoundedPlane bp) { var dpExtents = new Vector2(dp.ExtentX, dp.ExtentZ); var extents = Vector2.Distance(dpExtents, bp.extents) > 0.005f; var rotation = dp.CenterPose.rotation != bp.rotation; var position = Vector2.Distance(dp.CenterPose.position, bp.center) > 0.005f; return(extents || rotation || position); }
protected virtual void PlaneRemovedHandler(BoundedPlane plane) { GameObject go; if (m_Planes.TryGetValue(plane.id, out go)) { Destroy(go); m_Planes.Remove(plane.id); } }
void UpdateARPlane(BoundedPlane arPlane) { if (_planeId == null) { _planeId = arPlane.id; } if (arPlane.id == _planeId) { _cachedARPlane = arPlane; } returnARPlane(_cachedARPlane); }
protected virtual void CreateOrUpdateGameObject(BoundedPlane plane) { GameObject go; if (!m_Planes.TryGetValue(plane.id, out go)) { go = Instantiate(m_PlanePrefab, GetRoot()); // Make sure we can pick them later foreach (var collider in go.GetComponentsInChildren <Collider>()) { collider.gameObject.layer = m_PlaneLayer; } m_Planes.Add(plane.id, go); } go.transform.localPosition = plane.center; go.transform.localRotation = plane.rotation; go.transform.localScale = new Vector3(plane.extents.x, 1f, plane.extents.y); }
public override IEnumerator StartService(Settings settings) { m_CameraPose = Pose.identity; m_CameraPose.position.Set(0, 0, 0); m_LastTime = Time.time; m_State = State.Initialized; m_FakePlanes = new BoundedPlane[2]; m_FakePlanes[0] = new BoundedPlane() { id = "0x1", extents = new Vector2(2.2f, 2f), //extents = new Vector2(1f, 1f), rotation = Quaternion.AngleAxis(60f, Vector3.up), center = new Vector3(2f, -1f, 3f) //center = new Vector3(1f, 1f, 1f) }; m_FakePlanes[1] = new BoundedPlane() { id = "0x2", extents = new Vector2(2f, 2f), rotation = Quaternion.AngleAxis(200f, Vector3.up), center = new Vector3(3f, 1f, 3f) }; m_PointCloud = new Vector3[20]; for (int i = 0; i < 20; ++i) { m_PointCloud[i] = new Vector3( UnityEngine.Random.Range(-2f, 2f), UnityEngine.Random.Range(-.5f, .5f), UnityEngine.Random.Range(-2f, 2f)); } IsRunning = true; return(null); }
public override void Update() { if (m_SessionManager == null) { return; } AsyncTask.OnUpdate(); if (Frame.TrackingState != TrackingState.Tracking) { return; } Frame.GetPlanes(m_TrackedPlaneBuffer); foreach (var trackedPlane in m_TrackedPlaneBuffer) { BoundedPlane boundedPlane; if (m_TrackedPlanes.TryGetValue(trackedPlane, out boundedPlane)) { // remove any subsumed planes if (trackedPlane.SubsumedBy != null) { OnPlaneRemoved(boundedPlane); m_TrackedPlanes.Remove(trackedPlane); } // update any planes with changed extents else if (PlaneUpdated(trackedPlane, boundedPlane)) { boundedPlane.center = trackedPlane.Position; boundedPlane.rotation = trackedPlane.Rotation; boundedPlane.extents.x = trackedPlane.ExtentX; boundedPlane.extents.y = trackedPlane.ExtentZ; OnPlaneUpdated(boundedPlane); } } // add any new planes else { boundedPlane = new BoundedPlane() { id = Guid.NewGuid().ToString(), center = trackedPlane.Position, rotation = trackedPlane.Rotation, extents = new Vector2(trackedPlane.ExtentX, trackedPlane.ExtentZ) }; m_TrackedPlanes.Add(trackedPlane, boundedPlane); OnPlaneAdded(boundedPlane); } } // Check for planes that were removed from the tracked plane list List <TrackedPlane> planesToRemove = new List <TrackedPlane>(); foreach (var kvp in m_TrackedPlanes) { var trackedPlane = kvp.Key; if (!m_TrackedPlaneBuffer.Exists(x => x == trackedPlane)) { OnPlaneRemoved(kvp.Value); planesToRemove.Add(trackedPlane); } } foreach (var plane in planesToRemove) { m_TrackedPlanes.Remove(plane); } }
public void PlaneRemovedHandler(BoundedPlane plane) { SerializableBoundedPlane serializedPlane = plane; SendToEditor(ARMessageIds.removePlane, serializedPlane); }
public override void Update() { if (m_ARCoreSession == null) { return; } AsyncTask.OnUpdate(); if (Session.Status != SessionStatus.Tracking) { return; } if (m_ARCoreSessionConfig.PlaneFindingMode != DetectedPlaneFindingMode.Disabled) { Session.GetTrackables <DetectedPlane>(m_TrackedPlaneBuffer, TrackableQueryFilter.All); foreach (var trackedPlane in m_TrackedPlaneBuffer) { BoundedPlane boundedPlane; if (m_TrackedPlanes.TryGetValue(trackedPlane, out boundedPlane)) { // remove any subsumed planes if (trackedPlane.SubsumedBy != null) { OnPlaneRemoved(boundedPlane); m_TrackedPlanes.Remove(trackedPlane); } // update any planes with changed extents else if (PlaneUpdated(trackedPlane, boundedPlane)) { boundedPlane.center = trackedPlane.CenterPose.position; boundedPlane.rotation = trackedPlane.CenterPose.rotation; boundedPlane.extents.x = trackedPlane.ExtentX; boundedPlane.extents.y = trackedPlane.ExtentZ; m_TrackedPlanes[trackedPlane] = boundedPlane; OnPlaneUpdated(boundedPlane); } } // add any new planes else { boundedPlane = new BoundedPlane() { id = Guid.NewGuid().ToString(), center = trackedPlane.CenterPose.position, rotation = trackedPlane.CenterPose.rotation, extents = new Vector2(trackedPlane.ExtentX, trackedPlane.ExtentZ) }; m_TrackedPlanes.Add(trackedPlane, boundedPlane); OnPlaneAdded(boundedPlane); } } // Check for planes that were removed from the tracked plane list List <DetectedPlane> planesToRemove = new List <DetectedPlane>(); foreach (var kvp in m_TrackedPlanes) { var trackedPlane = kvp.Key; if (!m_TrackedPlaneBuffer.Exists(x => x == trackedPlane)) { OnPlaneRemoved(kvp.Value); planesToRemove.Add(trackedPlane); } } foreach (var plane in planesToRemove) { m_TrackedPlanes.Remove(plane); } } //Update Anchors foreach (var anchor in m_Anchors) { anchor.Key.transform.position = anchor.Value.transform.position; anchor.Key.transform.rotation = anchor.Value.transform.rotation; } }
public override void Update() { SessionManager.Instance.EarlyUpdate(); if (Frame.TrackingState != FrameTrackingState.Tracking) { return; } Frame.GetAllPlanes(ref m_TrackedPlaneBuffer); foreach (var trackedPlane in m_TrackedPlaneBuffer) { if (trackedPlane.IsUpdated) { BoundedPlane boundedPlane; if (m_TrackedPlanes.TryGetValue(trackedPlane, out boundedPlane)) { if (trackedPlane.SubsumedBy == null) { OnPlaneUpdated(boundedPlane); } else { OnPlaneRemoved(boundedPlane); m_TrackedPlanes.Remove(trackedPlane); } } else { boundedPlane = new BoundedPlane() { id = Guid.NewGuid().ToString(), center = trackedPlane.Position, rotation = trackedPlane.Rotation, extents = trackedPlane.Bounds }; m_TrackedPlanes.Add(trackedPlane, boundedPlane); OnPlaneAdded(boundedPlane); } } } // Check for planes that were removed from the tracked plane list List <TrackedPlane> planesToRemove = new List <TrackedPlane>(); foreach (var kvp in m_TrackedPlanes) { var trackedPlane = kvp.Key; if (!m_TrackedPlaneBuffer.Exists(x => x == trackedPlane)) { OnPlaneRemoved(kvp.Value); // Add to list here to avoid mutating the dictionary // while iterating over it. planesToRemove.Add(trackedPlane); } } foreach (var plane in planesToRemove) { m_TrackedPlanes.Remove(plane); } }
public override void Update() { if (m_ARCoreSession == null) { return; } AsyncTask.OnUpdate(); if (lastFrameTrackingState == SessionStatus.Tracking && Session.Status != SessionStatus.Tracking && !_trackingLostCountdownInProgress) { //Debounce - if we regain tracking within a second, just send it as a TrackingJumped event - less disruptive that completely losing tracking. Mapbox.Unity.Utilities.Console.Instance.Log("Tracking lost (changed from " + lastFrameTrackingState + " to " + Session.Status + "), starting countdown timer", "yellow"); _trackingLostCountdownInProgress = true; _trackingLostLastPose = Frame.Pose; _trackingLostTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } if (Session.Status != lastFrameTrackingState && Session.Status == SessionStatus.Tracking) { if (!_trackingLostCountdownInProgress) { OnTrackingStarted(Frame.Pose); } else { //Regained tracking within a second, send a jump. long timeNow = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; Mapbox.Unity.Utilities.Console.Instance.Log("Tracking recovered after " + (timeNow - _trackingLostTime) + "ms, sending a TrackingJump instead of TrackingLost & TrackingStart. ", "yellow"); OnTrackingJumped(Frame.Pose, lastFramePose); _trackingLostCountdownInProgress = false; _trackingLostLastPose = new Pose(); _trackingLostTime = 0; } } if (lastFrameTrackingState == SessionStatus.Tracking && //Do not fire "OnTrackingJumped" on the first frame when tracking just started (OnTrackingStarted will fire instead, see above). Session.Status == SessionStatus.Tracking && ((Frame.Pose.position - lastFramePose.position).magnitude > 1 || Quaternion.Angle(Frame.Pose.rotation, lastFramePose.rotation) > 30) ) { Mapbox.Unity.Utilities.Console.Instance.Log(string.Format("Jump strength: position: {0}m, rotation: {1} degrees ", (Frame.Pose.position - lastFramePose.position).magnitude, Quaternion.Angle(Frame.Pose.rotation, lastFramePose.rotation)), "yellow"); OnTrackingJumped(Frame.Pose, lastFramePose); } //Check if trackingLost timer expired if (Session.Status != SessionStatus.Tracking && _trackingLostCountdownInProgress) { long timeNow = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (timeNow - _trackingLostTime >= 1000) { Mapbox.Unity.Utilities.Console.Instance.Log("Tracking lost timer expired after " + (timeNow - _trackingLostTime) + "ms, sending TrackingLost", "yellow"); OnTrackingLost(_trackingLostLastPose); _trackingLostCountdownInProgress = false; _trackingLostLastPose = new Pose(); _trackingLostTime = 0; } } //Save frameTrackingState so we can compare on next frame & detect changes. lastFrameTrackingState = Session.Status; if (Session.Status == SessionStatus.Tracking) { lastFramePose = Frame.Pose; } if (Session.Status != SessionStatus.Tracking) { return; } if (m_ARCoreSessionConfig.EnablePlaneFinding) { Session.GetTrackables <TrackedPlane>(m_TrackedPlaneBuffer, TrackableQueryFilter.All); foreach (var trackedPlane in m_TrackedPlaneBuffer) { BoundedPlane boundedPlane; if (m_TrackedPlanes.TryGetValue(trackedPlane, out boundedPlane)) { // remove any subsumed planes if (trackedPlane.SubsumedBy != null) { OnPlaneRemoved(boundedPlane); m_TrackedPlanes.Remove(trackedPlane); } // update any planes with changed extents else if (PlaneUpdated(trackedPlane, boundedPlane)) { boundedPlane.center = trackedPlane.CenterPose.position; boundedPlane.rotation = trackedPlane.CenterPose.rotation; boundedPlane.extents.x = trackedPlane.ExtentX; boundedPlane.extents.y = trackedPlane.ExtentZ; m_TrackedPlanes[trackedPlane] = boundedPlane; OnPlaneUpdated(boundedPlane); } } // add any new planes else { boundedPlane = new BoundedPlane() { id = Guid.NewGuid().ToString(), center = trackedPlane.CenterPose.position, rotation = trackedPlane.CenterPose.rotation, extents = new Vector2(trackedPlane.ExtentX, trackedPlane.ExtentZ) }; m_TrackedPlanes.Add(trackedPlane, boundedPlane); OnPlaneAdded(boundedPlane); } } // Check for planes that were removed from the tracked plane list List <TrackedPlane> planesToRemove = new List <TrackedPlane>(); foreach (var kvp in m_TrackedPlanes) { var trackedPlane = kvp.Key; if (!m_TrackedPlaneBuffer.Exists(x => x == trackedPlane)) { OnPlaneRemoved(kvp.Value); planesToRemove.Add(trackedPlane); } } foreach (var plane in planesToRemove) { m_TrackedPlanes.Remove(plane); } } //Update Anchors foreach (var anchor in m_Anchors) { anchor.Key.transform.position = anchor.Value.transform.position; anchor.Key.transform.rotation = anchor.Value.transform.rotation; } }