public async void StartPolling(int updateFrequencyMs) { SceneUnderstandingState.UpdateState("Started Polling"); isPolling = true; await new WaitForBackgroundThread(); try { while (isPolling) { SceneUnderstandingState.UpdateState("Fetching a scene"); Scene = sceneFetcher.FetchScene(); SceneUnderstandingState.UpdateState("Waiting for main thread"); await new WaitForUpdate(); SceneUnderstandingState.UpdateState("Invoking callbacks"); onScene.Invoke(); SceneUnderstandingState.UpdateState("Waiting for background for next poll"); await new WaitForBackgroundThread(); SceneUnderstandingState.UpdateState("Waiting for next poll"); await Task.Delay(updateFrequencyMs); } SceneUnderstandingState.UpdateState("Polling ended gracefully"); } catch (Exception ex) { Debug.LogException(ex); Debug.LogError("Error in scene understanding: " + ex.Message); SceneUnderstandingState.UpdateErrors(ex, "Error when polling"); await new WaitForUpdate(); } }
public Scene FetchScene() { var querySettings = Prepare(); SceneUnderstandingState.UpdateState("Querying scene"); var fetchSceneTask = lastScene == null ? SceneObserver.ComputeAsync(querySettings, SearchRadius) : SceneObserver.ComputeAsync(querySettings, SearchRadius, lastScene); var scene = fetchSceneTask.GetAwaiter().GetResult(); SceneUnderstandingState.UpdateState("Scene bytes queried"); return(scene); }
public byte[] FetchSceneBytes() { var querySettings = Prepare(); SceneUnderstandingState.UpdateState("Querying scene bytes..."); var fetchSceneTask = SceneObserver.ComputeSerializedAsync(querySettings, SearchRadius); var sceneBuffer = fetchSceneTask.GetAwaiter().GetResult(); SceneUnderstandingState.UpdateState("Scene bytes queried"); var data = new byte[sceneBuffer.Size]; sceneBuffer.GetData(data); return(data); }
private SceneQuerySettings Prepare() { SceneUnderstandingState.UpdateState("Requesting access"); var status = SceneObserver.RequestAccessAsync().GetAwaiter().GetResult(); if (status != SceneObserverAccessStatus.Allowed) { SceneUnderstandingState.UpdateState($"FAILED - no access: {status}"); throw new Exception($"Expected to get access. Actually got: " + status); } var querySettings = new SceneQuerySettings() { EnableWorldMesh = false, EnableSceneObjectMeshes = false, EnableSceneObjectQuads = true, RequestedMeshLevelOfDetail = SceneMeshLevelOfDetail.Coarse, EnableOnlyObservedSceneObjects = false }; return(querySettings); }
public void TakeSnapshot() { SceneUnderstandingState.UpdateState("Taking snapshot"); Scene = sceneFetcher.FetchScene(); onScene.Invoke(); }
public void StopPolling() { SceneUnderstandingState.UpdateState("Stopping Polling"); isPolling = false; }