Beispiel #1
0
        public static async Task <bool> ExportAnchors(this WindowsMRAnchorSubsystem wmrrp, Stream output)
        {
            bool ret = false;

#if ENABLE_WINMD_SUPPORT
            try
            {
                Debug.Log($"Getting Spatial Anchor Transfer Manager Access");
                var access = await SpatialAnchorTransferManager.RequestAccessAsync();

                if (access != SpatialPerceptionAccessStatus.Allowed)
                {
                    Debug.Log($"Access check failed with {access}");
                    return(ret);
                }

                Debug.Log($"Getting Spatial Anchor Store");
                var spatialAnchorStore = await SpatialAnchorManager.RequestStoreAsync();

                if (spatialAnchorStore == null)
                {
                    return(ret);
                }

                Debug.Log($"Setting up stream");
                var stream = output.AsOutputStream();

                Debug.Log($"Getting saved anchors");
                var anchors = spatialAnchorStore.GetAllSavedAnchors();
                if (anchors == null || anchors.Count == 0)
                {
                    Debug.Log("No anchors to exort!!!");
                }
                else
                {
                    Debug.Log("Exporting anchors...");
                    ret = await SpatialAnchorTransferManager.TryExportAnchorsAsync(anchors, stream);

                    Debug.Log(ret ? "SUCCESS" : "FAILURE");
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
                ret = false;
            }
#else
            Debug.LogError("This API is only available for use in UWP based applications.");
#endif //ENABLE_WINMD_SUPPORT
            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes static members of the <see cref="MixedReality"/> class.
        /// Attempts to initialize the world coordinate system from a given spatial anchor.
        /// If no spatial anchor is given, it attempts to load a default spatial anchor.
        /// If the default spatial anchor is not found (e.g., if the app is being run for the first time),
        /// a stationary frame of reference for the world is created at the current location.
        /// </summary>
        /// <param name="worldSpatialAnchor">A spatial anchor to use for the world (optional).</param>
        /// <param name="regenerateDefaultWorldSpatialAnchorIfNeeded">Optional flag indicating whether to regenerate and persist default world spatial anchor if currently persisted anchor fails to localize in the current environment (default: false).</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <remarks>
        /// This method should be called after SK.Initialize.
        /// </remarks>
        public static async Task InitializeAsync(SpatialAnchor worldSpatialAnchor = null, bool regenerateDefaultWorldSpatialAnchorIfNeeded = false)
        {
            if (!SK.IsInitialized)
            {
                throw new InvalidOperationException("StereoKit is not initialized. Call SK.Initialize before calling MixedReality.InitializeAsync.");
            }

            // Create the spatial anchor helper
            SpatialAnchorHelper = new SpatialAnchorHelper(await SpatialAnchorManager.RequestStoreAsync());

            InitializeWorldCoordinateSystem(worldSpatialAnchor, regenerateDefaultWorldSpatialAnchorIfNeeded);

            // By default, don't render the hands or register with StereoKit physics system.
            Input.HandVisible(Handed.Max, false);
            Input.HandSolid(Handed.Max, false);
        }
Beispiel #3
0
#pragma warning disable CS0618
#pragma warning disable CS1998
        public static async Task <bool> ImportAnchors(this WindowsMRAnchorSubsystem wmrrp, Stream input)
        {
            bool ret = false;

#if ENABLE_WINMD_SUPPORT
            try
            {
                var access = await SpatialAnchorTransferManager.RequestAccessAsync();

                if (access != SpatialPerceptionAccessStatus.Allowed)
                {
                    return(ret);
                }

                var spatialAnchorStore = await SpatialAnchorManager.RequestStoreAsync();

                if (spatialAnchorStore == null)
                {
                    return(ret);
                }

                var anchors = await SpatialAnchorTransferManager.TryImportAnchorsAsync(input.AsInputStream());

                foreach (var kvp in anchors)
                {
                    spatialAnchorStore.TrySave(kvp.Key, kvp.Value);
                }

                ret = true;
            }
            catch (Exception e)
            {
                Debug.Log(e);
                ret = false;
            }
#else
            Debug.LogError("This API is only available for use in UWP based applications.");
#endif //ENABLE_WINMD_SUPPORT
            return(ret);
        }
    private async Task GetStoreAsync()
    {
        anchorStore = await SpatialAnchorManager.RequestStoreAsync();

        LoadAnchors();
    }