/// <summary> /// Gets a reference to the ViewModel and the ArFragment /// </summary> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e) { try { base.OnElementChanged(e); var activity = this.Context as Activity; this.viewModel = this.Element.BindingContext as AnchorsViewModel; // Gets the view and setups the AR fragment this.view = activity.LayoutInflater.Inflate(Resource.Layout.AnchorsLayout, this, false); AddView(this.view); this.arFragment = activity.GetFragmentManager().FindFragmentById(Resource.Id.anchors_fragment) as AnchorsFragment; if (this.arFragment != null) { this.arFragment.ArSceneView.Scene.Update += (_, args) => { // Passes the frame to the viewmodels // this's needed for the spatial anchors session this.viewModel.ProcessFrame(this.arFragment.ArSceneView.ArFrame); }; // Starts the session this.viewModel.StartSession(this.Context, this.arFragment); } } catch (Exception ex) { this.viewModel.ShowMessage("UnableToStartArSession", ex.Message); } }
/// <summary> /// Setup the frame for the sceneview /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); this.viewModel = this.Element.BindingContext as AnchorsViewModel; this.sceneView = new ARSCNView { Frame = this.View.Frame, UserInteractionEnabled = true, }; this.sceneView.Delegate = new ArSessionDelegate(this.sceneView, this.viewModel); this.View.AddSubview(this.sceneView); }
public ArSessionDelegate(ARSCNView sceneView, AnchorsViewModel viewmodel) { this.sceneView = sceneView; this.viewModel = viewmodel; }