Пример #1
0
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(hitResult.CreateAnchor());

            visual.SetColor(readyColorMaterial);
            visual.AddToScene(this.arFragment);
            this.anchorVisuals[string.Empty] = visual;

            this.RunOnUiThread(() =>
            {
                this.scanProgressText.Visibility = ViewStates.Visible;
                if (this.enoughDataForSaving)
                {
                    this.statusText.Text         = "Ready to save";
                    this.actionButton.Text       = "Save cloud anchor";
                    this.actionButton.Visibility = ViewStates.Visible;
                }
                else
                {
                    this.statusText.Text = "Move around the anchor";
                }
            });

            this.currentDemoStep = DemoStep.SaveAnchor;

            return(visual.LocalAnchor);
        }
Пример #2
0
        private void AnchorSaveFailed(string message)
        {
            this.RunOnUiThread(() => this.statusText.Text = message);
            AnchorVisual visual = this.anchorVisuals[string.Empty];

            visual.SetColor(failedColorMaterial);
        }
Пример #3
0
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(hitResult.CreateAnchor());

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

            return(visual.LocalAnchor);
        }
Пример #4
0
        private void AnchorLookedUp(string anchorId)
        {
            Log.Debug("ASADemo", "anchor " + anchorId);
            this.anchorId = anchorId;
            this.DestroySession();

            bool anchorLocated = false;

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

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    anchorLocated = true;

                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };
                    foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.AddToScene(this.arFragment);
                    this.anchorVisuals[cloudAnchorIdentifier] = foundVisual;
                }
            });

            this.cloudAnchorManager.OnLocateAnchorsCompleted += (sender, args) =>
            {
                this.currentStep = DemoStep.Start;

                this.RunOnUiThread(() =>
                {
                    if (anchorLocated)
                    {
                        this.textView.Text = "Anchor located!";
                    }
                    else
                    {
                        this.textView.Text = "Anchor was not located. Check the logs for errors and\\or create a new anchor and try again.";
                    }

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

            criteria.SetIdentifiers(new string[] { anchorId });
            this.cloudAnchorManager.StartLocating(criteria);
        }
Пример #5
0
        private void RenderLocatedAnchor(CloudSpatialAnchor anchor)
        {
            AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
            {
                CloudAnchor = anchor
            };

            foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
            string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;

            foundVisual.SetColor(foundColorMaterial);
            foundVisual.AddToScene(this.arFragment);
            this.anchorVisuals[cloudAnchorIdentifier] = foundVisual;
        }
Пример #6
0
        private void SetupLocalCloudAnchor(AnchorVisual visual)
        {
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor
            {
                LocalAnchor = visual.LocalAnchor
            };

            visual.CloudAnchor = cloudAnchor;

            // In this sample app we delete the cloud anchor explicitly, but you can also set it to expire automatically
            Date     now = new Date();
            Calendar cal = Calendar.Instance;

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

            cloudAnchor.Expiration = oneWeekFromNow;
        }
Пример #7
0
        private void TransitionToSaving(AnchorVisual visual)
        {
            Log.Debug("ASADemo:", "transition to saving");
            this.currentStep = DemoStep.SavingAnchor;
            this.EnableCorrectUIControls();
            Log.Debug("ASADemo", "creating anchor");
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

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

            this.cloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo:", "created anchor: " + anchorId);
                    visual.SetColor(savedColor);
                    this.anchorVisuals[anchorId] = visual;
                    this.anchorVisuals.TryRemove(string.Empty, out _);

                    Log.Debug("ASADemo", "recording anchor with web service");
                    Log.Debug("ASADemo", "anchorId: " + anchorId);
                    SendAnchorResponse response = await this.anchorSharingServiceClient.SendAnchorIdAsync(anchorId, anchorNumInput.Text);
                    this.AnchorPosted(response.AnchorNumber);
                }
                catch (CloudSpatialException ex)
                {
                    this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception ex)
                {
                    this.CreateAnchorExceptionCompletion(ex.Message);
                    visual.SetColor(failedColor);
                }
            });
        }
Пример #8
0
        private void AnchorSaveSuccess(CloudSpatialAnchor result)
        {
            this.saveCount++;

            this.anchorID = result.Identifier;
            Log.Debug("ASADemo:", "created anchor: " + this.anchorID);

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

            visual.SetColor(savedColorMaterial);
            this.anchorVisuals[this.anchorID] = visual;
            this.anchorVisuals.TryRemove(string.Empty, out _);

            if (this.basicDemo || this.saveCount == numberOfNearbyAnchors)
            {
                this.RunOnUiThread(() =>
                {
                    this.statusText.Text         = string.Empty;
                    this.actionButton.Visibility = ViewStates.Visible;
                });

                this.currentDemoStep = DemoStep.StopSession;
                this.AdvanceDemo();
            }
            else
            {
                // Need to create more anchors for nearby demo
                this.RunOnUiThread(() =>
                {
                    this.statusText.Text         = "Tap a surface to create next anchor";
                    this.actionButton.Visibility = ViewStates.Invisible;
                });

                this.currentDemoStep = DemoStep.CreateAnchor;
            }
        }