public void OnCreateButtonClicked(object sender, EventArgs args)
        {
            if (currentStep == DemoStep.MindrStart)
            {
                DestroySession();

                currentStep       = DemoStep.MindrName;
                textView.Text     = "Name your MindR!";
                createButton.Text = "Set name";
                EnableCorrectUIControls();
            }

            if (currentStep == DemoStep.MindrName)
            {
                if (string.IsNullOrWhiteSpace(anchorNumInput.Text))
                {
                    textView.Text = "Please name your MindR";
                    return;
                }

                createButton.Text = "Save";

                textView.Text = "Scan your environment and place a MindR";
                DestroySession();

                cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session);

                cloudAnchorManager.OnSessionUpdated += (_, sessionUpdateArgs) =>
                {
                    SessionStatus status = sessionUpdateArgs.Status;

                    if (currentStep == DemoStep.MindrCreate)
                    {
                        float progress = status.RecommendedForCreateProgress;
                        if (progress >= 1.0)
                        {
                            if (anchorVisuals.TryGetValue(string.Empty, out AnchorVisual visual))
                            {
                                //Transition to saving...
                                TransitionToSaving(visual);
                            }
                            else
                            {
                                feedbackText = "Tap somewhere to place a MindR.";
                            }
                        }
                        else
                        {
                            feedbackText = $"Progress is {progress:0%}";
                        }
                    }
                };

                currentStep = DemoStep.MindrCreate;
                EnableCorrectUIControls();

                cloudAnchorManager.StartSession();
            }
        }
Esempio n. 2
0
 private void CreateAnchorExceptionCompletion(string message)
 {
     this.textView.Text = message;
     this.currentStep   = DemoStep.Start;
     this.cloudAnchorManager.StopSession();
     this.cloudAnchorManager = null;
     this.EnableCorrectUIControls();
 }
        private void StartNewSession()
        {
            this.DestroySession();

            this.cloudAnchorManager = new AzureSpatialAnchorsManager(this.sceneView.Session);
            this.cloudAnchorManager.OnAnchorLocated          += this.OnAnchorLocated;
            this.cloudAnchorManager.OnLocateAnchorsCompleted += this.OnLocateAnchorsCompleted;
            this.cloudAnchorManager.OnSessionUpdated         += this.OnSessionUpdated;
            this.cloudAnchorManager.StartSession();
        }
        private void DestroySession()
        {
            if (this.cloudAnchorManager != null)
            {
                this.cloudAnchorManager.StopSession();
                this.cloudAnchorManager = null;
            }

            this.ClearVisuals();
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 private void AnchorPosted(string anchorNumber)
 {
     this.RunOnUiThread(() =>
     {
         this.textView.Text = "Anchor Number: " + anchorNumber;
         this.currentStep   = DemoStep.Start;
         this.cloudAnchorManager.StopSession();
         this.cloudAnchorManager = null;
         this.ClearVisuals();
         this.EnableCorrectUIControls();
     });
 }
        private void DestroySession()
        {
            if (cloudAnchorManager != null)
            {
                cloudAnchorManager.StopSession();
                cloudAnchorManager = null;
            }

            StopWatcher();

            ClearVisuals();
        }
 private void AnchorPosted(string anchorNumber)
 {
     RunOnUiThread(() =>
     {
         textView.Text = "MindR saved, pasted url on clipboard";
         currentStep   = DemoStep.MindrStart;
         cloudAnchorManager.StopSession();
         cloudAnchorManager = null;
         ClearVisuals();
         EnableCorrectUIControls();
         createButton.Text = "Create";
     });
 }
Esempio n. 9
0
        protected override void OnPause()
        {
            sensorStatusView.Model = null;

            if (cloudAnchorManager != null)
            {
                cloudAnchorManager.StopSession();
                cloudAnchorManager = null;
            }
            locationProvider = null;

            base.OnPause();
        }
        protected override void OnResume()
        {
            base.OnResume();

            // ArFragment of Sceneform automatically requests the camera permission before creating the AR session,
            // so we don't need to request the camera permission explicitly.
            // This will cause onResume to be called again after the user responds to the permission request.
            if (!SceneformHelper.HasCameraPermission(this))
            {
                return;
            }

            if (sceneView?.Session is null && !SceneformHelper.TrySetupSessionForSceneView(this, sceneView))
            {
                // Exception will be logged and SceneForm will handle any ARCore specific issues.
                Finish();
                return;
            }

            if (string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountId) || AccountDetails.SpatialAnchorsAccountId == "Set me" ||
                string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountKey) || AccountDetails.SpatialAnchorsAccountKey == "Set me" ||
                string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountDomain) || AccountDetails.SpatialAnchorsAccountDomain == "Set me")
            {
                Toast.MakeText(this, $"\"Set {AccountDetails.SpatialAnchorsAccountId}, {AccountDetails.SpatialAnchorsAccountKey}, and {AccountDetails.SpatialAnchorsAccountDomain} in {nameof(AccountDetails)}.cs\"", ToastLength.Long)
                .Show();

                Finish();
                return;
            }

            SensorPermissionsHelper.RequestMissingPermissions(this);

            cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session);
            cloudAnchorManager.StartSession();

            locationProvider = new PlatformLocationProvider();
            locationProvider.Sensors.SetKnownBeaconProximityUuids(CoarseRelocSettings.KnownBluetoothProximityUuids);
            SensorPermissionsHelper.EnableAllowedSensors(this, locationProvider);
            cloudAnchorManager.LocationProvider = locationProvider;

            sensorStatusView.Model = new LocationProviderSensorStatus(locationProvider);
        }
Esempio n. 11
0
        public void OnCreateButtonClicked(object sender, EventArgs args)
        {
            this.textView.Text = "Scan your environment and place an anchor";
            this.DestroySession();

            this.cloudAnchorManager = new AzureSpatialAnchorsManager(this.sceneView.Session);

            this.cloudAnchorManager.OnSessionUpdated += (_, sessionUpdateArgs) =>
            {
                SessionStatus status = sessionUpdateArgs.Status;

                if (this.currentStep == DemoStep.CreateAnchor)
                {
                    float progress = status.RecommendedForCreateProgress;
                    if (progress >= 1.0)
                    {
                        if (this.anchorVisuals.TryGetValue(string.Empty, out AnchorVisual visual))
                        {
                            //Transition to saving...
                            this.TransitionToSaving(visual);
                        }
                        else
                        {
                            this.feedbackText = "Tap somewhere to place an anchor.";
                        }
                    }
                    else
                    {
                        this.feedbackText = $"Progress is {progress:0%}";
                    }
                }
            };

            this.cloudAnchorManager.StartSession();
            this.currentStep = DemoStep.CreateAnchor;
            this.EnableCorrectUIControls();
        }
        public async void LocateAllAnchors()
        {
            await Task.Delay(2000);

            textView.Text = "Searching for MindRs...";

            // clean up prev session just in case
            DestroySession();

            // start locating
            cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session);

            var anchorLocated = false;

            cloudAnchorManager.OnAnchorLocated += (sender, args) =>
                                                  RunOnUiThread(async() =>
            {
                CloudSpatialAnchor anchor = args.Anchor;
                LocateAnchorStatus status = args.Status;

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };

                    var mr = await _mindrService.TryGetContentsForAnchor(anchor.Identifier);
                    textView.Visibility = ViewStates.Visible;
                    textView.Text       = mr != null ? mr.actualDesc : "No data found for MindR.";

                    foundVisual.AnchorNode.SetParent(arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.AddToScene(arFragment, textView.Text);
                    anchorVisuals[cloudAnchorIdentifier] = foundVisual;


                    foundVisual.AnchorNode.SetOnTouchListener(this);
                    anchorLocated = true;
                }
            });

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

                RunOnUiThread(() =>
                {
                    textView.Text = anchorLocated ? "MindR(s) located!" : "Failed to find any MindRs.";

                    EnableCorrectUIControls();
                });
            };

            cloudAnchorManager.StartSession();

            await Task.Delay(2000);

            var ac  = new AnchorLocateCriteria();
            var ids = await _mindrService.GetAllAnchorIds();

            ac.SetIdentifiers(ids.ToArray());
            cloudAnchorManager.StartLocating(ac);
        }