/// <summary> /// Coroutine that spreads the work of displaying scene objects across multiple frames. /// </summary> /// <returns>IEnumerator.</returns> private IEnumerator DisplayData() { StatusText.Clear(); StatusText.Append("About to display the latest set of scene objects."); StatusText.Append(string.Format("Current Settings:-\n\tRenderSceneObjects: {0}; SceneObjectVisualizationMode: {1}; RenderInferredRegions: {2};\n\tRenderPlatform: {3}; RenderBackground: {4}; RenderUnknown: {5}; RenderCompletelyInferred: {6};\n\tRenderWorldMesh: {7}; WorldMeshLOD: {8};\n\tBoundingSphereRadiusInMeters: {9};", RenderSceneObjects, SceneObjectVisualizationMode.ToString(), SUDataProvider.RequestInferredRegions, RenderPlatformSceneObjects, RenderBackgroundSceneObjects, RenderUnknownSceneObjects, RenderCompletelyInferredSceneObjects, RenderWorldMesh, SUDataProvider.WorldMeshLOD.ToString(), SUDataProvider.BoundingSphereRadiusInMeters)); // First, get the latest scene from the data provider. Tuple <Guid, byte[]> latestSceneData = SUDataProvider.GetLatestSerializedScene(); byte[] serializedScene = latestSceneData.Item2; if (serializedScene != null) { // Then, deserialize the scene. SceneUnderstanding.Scene scene = SceneUnderstanding.Scene.Deserialize(serializedScene); if (scene != null) { // This will destroy all game objects under root. SUUtils.DestroyAllGameObjectsUnderParent(SceneRoot.transform); // Return to account for the destruction of the game objects at the end of the frame. yield return(null); // Retrieve the Scene to Unity world transform. System.Numerics.Matrix4x4?sceneToUnityTransform = TransformUtils.GetSceneToUnityTransform(scene.OriginSpatialGraphNodeId, SUDataProvider.RunOnDevice); if (sceneToUnityTransform != null) { // This will place the root object that represents the scene in the right place. TransformUtils.SetUnityTransformFromMatrix4x4(sceneToUnityTransform.Value, SceneRoot.transform); // Retrieve all the scene objects, associated with this scene. IEnumerable <SceneUnderstanding.SceneObject> sceneObjects = scene.SceneObjects; int i = 0; foreach (SceneUnderstanding.SceneObject sceneObject in sceneObjects) { if (DisplaySceneObject(sceneObject)) { ++i; if (i % 5 == 0) { yield return(null); } } } } // When running on PC, orient the main camera such that the floor is on the Unity world's X-Z plane. if (SUDataProvider.RunOnDevice == false) { SUUtils.OrientSceneRootForPC(SceneRoot, scene); } } } StatusText.Append("SceneUnderstandingDisplayManager.DisplayData: Display completed."); _displayInProgress = false; _lastDisplayedSceneGuid = latestSceneData.Item1; }