Ejemplo n.º 1
0
        /// <summary>
        /// Saves the <see cref="SceneUnderstanding.SceneProcessor"/>'s data stream as a file for later use
        /// </summary>
        /// <param name="sceneBuffer">the <see cref="byte[]"/></param>
        private async void SaveToFile(string prefix)
        {
            SceneQuerySettings sceneQuerySettings = new SceneQuerySettings()
            {
                EnableSceneObjectQuads         = true,
                EnableSceneObjectMeshes        = true,
                EnableOnlyObservedSceneObjects = false,
                EnableWorldMesh            = true,
                RequestedMeshLevelOfDetail = LevelOfDetailToMeshLOD(WorldMeshLevelOfDetail)
            };

            var serializedScene = SceneObserver.ComputeSerializedAsync(sceneQuerySettings, QueryRadius).GetAwaiter().GetResult();
            var bytes           = new byte[serializedScene.Size];

            serializedScene.GetData(bytes);
            var timestamp = DateTime.Now.ToString("yyyyMMdd_hhmmss");
            var filename  = $"SceneUnderStanding_{timestamp}.bytes";

            if (prefix != "")
            {
                filename = $"{prefix}_{timestamp}.bytes";
            }
            StorageFolder folderLocation = ApplicationData.Current.LocalFolder;
            IStorageFile  storageFile    = await folderLocation.CreateFileAsync(filename);

            await FileIO.WriteBytesAsync(storageFile, bytes);
        }
Ejemplo n.º 2
0
        private Scene GetSceneAsync(Scene previousScene)
        {
            Scene scene = null;

            if (Application.isEditor && ShouldLoadFromFile)
            {
                if (sceneBytes == null)
                {
                    Debug.LogError("sceneBytes is null!");
                }

                // Move onto a background thread for the expensive scene loading stuff

                if (UsePersistentObjects && previousScene != null)
                {
                    scene = Scene.Deserialize(sceneBytes, previousScene);
                }
                else
                {
                    // This happens first time through as we have no history yet
                    scene = Scene.Deserialize(sceneBytes);
                }
            }
            else
            {
                SceneQuerySettings sceneQuerySettings = new SceneQuerySettings()
                {
                    EnableSceneObjectQuads         = RequestPlaneData,
                    EnableSceneObjectMeshes        = RequestMeshData,
                    EnableOnlyObservedSceneObjects = !InferRegions,
                    EnableWorldMesh            = SurfaceTypes.HasFlag(SpatialAwarenessSurfaceTypes.World),
                    RequestedMeshLevelOfDetail = LevelOfDetailToMeshLOD(WorldMeshLevelOfDetail)
                };

                // Ideally you'd call SceneObserver.ComputeAsync() like this:
                // scene = await SceneObserver.ComputeAsync(...);
                // however this has has been problematic (buggy?)
                // For the time being we force it to be synchronous with the ...GetAwaiter().GetResult() pattern

                if (UsePersistentObjects)
                {
                    if (previousScene != null)
                    {
                        scene = SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius, previousScene).GetAwaiter().GetResult();
                    }
                    else
                    {
                        // first time through, we have no history
                        scene = SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius).GetAwaiter().GetResult();
                    }
                }
                else
                {
                    scene = SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius).GetAwaiter().GetResult();
                }
            }

            return(scene);
        }
Ejemplo n.º 3
0
    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);
    }