Beispiel #1
0
        private void TransitionToSaving(AnchorVisual visual)
        {
            Log.Debug("ASADemo:", "transition to saving");
            Log.Debug("ASADemo", "creating anchor");
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            visual.CloudAnchor      = cloudAnchor;
            cloudAnchor.LocalAnchor = visual.LocalAnchor;

            this.cloudSession.CreateAnchorAsync(cloudAnchor);
            Task.Run(() =>
            {
                try
                {
                    CloudSpatialAnchor anchor = cloudAnchor;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo:", "created anchor: " + anchorId);
                    visual.SetColor(savedColor);
                    this.anchorVisuals[anchorId] = visual;
                    this.anchorVisuals.TryRemove(string.Empty, out _);
                }
                catch (CloudSpatialException ex)
                {
                    this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception ex)
                {
                    this.CreateAnchorExceptionCompletion(ex.Message);
                    visual.SetColor(failedColor);
                }
            });
        }
Beispiel #2
0
        private void AnchorSaveFailed(string message)
        {
            this.RunOnUiThread(() => this.textView.Text = message);
            AnchorVisual visual = this.anchorVisuals[string.Empty];

            visual.SetColor(failedColor);
        }
Beispiel #3
0
        private void AnchorLookedUp(string anchorId)
        {
            this.DestroySession();

            this.cloudAnchorManager = new AzureSpatialAnchorsManager(this.sceneView.Session);
            this.cloudAnchorManager.OnAnchorLocated += (sender, args) =>
                                                       this.RunOnUiThread(() =>
            {
                CloudSpatialAnchor anchor = args.Args.Anchor;
                LocateAnchorStatus status = args.Args.Status;

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };
                    foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.Render(this.arFragment);
                    this.textView.Text = foundVisual.CloudAnchor.AppProperties["Label"];
                }
            });

            this.cloudAnchorManager.StartSession();
            AnchorLocateCriteria criteria = new AnchorLocateCriteria();

            criteria.SetIdentifiers(new string[] { anchorId });
            this.cloudAnchorManager.StartLocating(criteria);
        }
Beispiel #4
0
        private void AnchorSaveSuccess(CloudSpatialAnchor result)
        {
            this.anchorID = result.Identifier;
            Log.Debug("ASADemo:", "created anchor: " + this.anchorID);

            AnchorVisual visual = this.anchorVisuals[string.Empty];

            visual.SetColor(savedColor);
            this.anchorVisuals[this.anchorID] = visual;
            this.anchorVisuals.TryRemove(string.Empty, out _);
            var anchorNum = this.cloudAnchorManager.SendAnchorIdAsync(this.anchorID).Result;

            this.RunOnUiThread(() =>
            {
                this.textView.Text = String.Format("Created a cloud anchor with ID={0}", anchorNum);
            });
        }
Beispiel #5
0
        private void SetupLocalCloudAnchor(AnchorVisual visual)
        {
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor
            {
                LocalAnchor = visual.LocalAnchor
            };

            cloudAnchor.AppProperties.Add("Label", "Congrats! You found a spatial anchor");
            Date     now = new Date();
            Calendar cal = Calendar.Instance;

            cal.Time = now;
            cal.Add(CalendarField.Date, 7);
            Date oneWeekFromNow = cal.Time;

            cloudAnchor.Expiration = oneWeekFromNow;
            visual.CloudAnchor     = cloudAnchor;
        }
Beispiel #6
0
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(hitResult.CreateAnchor());

            visual.SetColor(readyColor);
            visual.Render(this.arFragment);
            this.anchorVisuals[string.Empty] = visual;

            this.RunOnUiThread(() =>
            {
                this.scanProgressText.Visibility = ViewStates.Visible;
                if (this.enoughDataForSaving)
                {
                    if (visual == null)
                    {
                        return;
                    }

                    if (!this.enoughDataForSaving)
                    {
                        return;
                    }

                    this.RunOnUiThread(() => this.exitButton.Visibility = ViewStates.Gone);

                    this.SetupLocalCloudAnchor(visual);

                    Task.Run(async() =>
                    {
                        try
                        {
                            CloudSpatialAnchor result = await this.cloudAnchorManager.CreateAnchorAsync(visual.CloudAnchor);
                            this.AnchorSaveSuccess(result);
                        }
                        catch (CloudSpatialException ex)
                        {
                            this.AnchorSaveFailed($"{ex.Message}, {ex.ErrorCode}");
                        }
                        catch (Exception ex)
                        {
                            this.AnchorSaveFailed(ex.Message);
                        }
                    });

                    lock (this.progressLock)
                    {
                        this.RunOnUiThread(() =>
                        {
                            this.scanProgressText.Visibility = ViewStates.Gone;
                            this.scanProgressText.Text       = string.Empty;
                            this.textView.Text = "Saving cloud anchor...";
                        });
                    }
                }
                else
                {
                    this.textView.Text = "Move around the anchor";
                }
            });
            this.exitButton.Visibility = ViewStates.Visible;
            return(visual.LocalAnchor);
        }