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(); } }
private void AnchorLookedUp(string anchorId) { Log.Debug("ASADemo", "anchor " + anchorId); this.anchorId = anchorId; DestroySession(); bool anchorLocated = false; cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session); cloudAnchorManager.OnAnchorLocated += (sender, args) => 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(arFragment.ArSceneView.Scene); string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier; foundVisual.SetColor(foundColor); foundVisual.AddToScene(arFragment); anchorVisuals[cloudAnchorIdentifier] = foundVisual; } }); cloudAnchorManager.OnLocateAnchorsCompleted += (sender, args) => { currentStep = DemoStep.Start; RunOnUiThread(() => { if (anchorLocated) { textView.Text = "Anchor located!"; } else { textView.Text = "Anchor was not located. Check the logs for errors and\\or create a new anchor and try again."; } EnableCorrectUIControls(); }); }; cloudAnchorManager.StartSession(); AnchorLocateCriteria criteria = new AnchorLocateCriteria(); criteria.SetIdentifiers(new string[] { anchorId }); cloudAnchorManager.StartLocating(criteria); }
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); }
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); }