private async void Init() { try { var p = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); var path = System.IO.Path.Combine(p, "philadelphia.mspk"); MobileScenePackage package = await MobileScenePackage.OpenAsync(path); // Load the package. await package.LoadAsync(); // Show the first scene. var scene = package.Scenes[0]; scene.BaseSurface.BackgroundGrid.IsVisible = false; scene.BaseSurface.NavigationConstraint = NavigationConstraint.None; ARView.Scene = scene; //We'll set the origin of the scene in the middle so we can use that as the tie-point ARView.OriginCamera = new Esri.ArcGISRuntime.Mapping.Camera(39.9579126, -75.1705827, 9.64, 0, 90, 0); ARView.TranslationFactor = 1000; // By increasing the translation factor, the scene appears as if it's at scale 1:1000 //Set the initial location 1.5 meter in front of and .5m above the scene ARView.SetInitialTransformation(TransformationMatrix.Create(0, 0, 0, 1, 0, .5, 1.5)); //Set the clipping distance to only render a circular area around the origin ARView.ClippingDistance = 350; //Listend for double-tap to place ARView.GeoViewDoubleTapped += ArView_GeoViewDoubleTapped; scene.OperationalLayers[0].Opacity = .5; } catch (System.Exception ex) { await DisplayAlert("Failed to load scene", ex.Message, "OK"); await Navigation.PopAsync(); } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); try { var p = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); var path = System.IO.Path.Combine(p, "philadelphia.mspk"); MobileScenePackage package = await MobileScenePackage.OpenAsync(path); // Load the package. await package.LoadAsync(); // Show the first scene. var scene = package.Scenes[0]; scene.BaseSurface.BackgroundGrid.IsVisible = false; scene.BaseSurface.NavigationConstraint = NavigationConstraint.None; ARView.Scene = scene; //We'll set the origin of the scene in the middle so we can use that as the tie-point ARView.OriginCamera = new Esri.ArcGISRuntime.Mapping.Camera(39.9579126, -75.1705827, 9.64, 0, 90, 0); ARView.TranslationFactor = 1000; // By increasing the translation factor, the scene appears as if it's at scale 1:1000 ARView.NorthAlign = false; //Set the clipping distance to only render a circular area around the origin ARView.ClippingDistance = 350; //Set the initial location 1.5 meter in front of and .5m above the scene ARView.SetInitialTransformation(TransformationMatrix.Create(0, 0, 0, 1, 0, .5, 1.5)); //Listen for double-tap to place ARView.GeoViewDoubleTapped += ArView_GeoViewDoubleTapped; } catch (System.Exception ex) { Toast.MakeText(this, "Failed to load scene: \n" + ex.Message, ToastLength.Long).Show(); } ToggleRenderPlanes(true); }
public async override void ViewDidLoad() { base.ViewDidLoad(); // Create a new AR Scene View, set its scene, and provide the coordinates for laying it out ARView = new ARSceneView(); // Add the ARSceneView to the Subview View.AddSubview(ARView); lbl = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false }; lbl.Text = "Move the device in a circular motion to detect surfaces..."; View.AddSubview(lbl); lbl.TopAnchor.ConstraintEqualTo(this.View.TopAnchor, 0).Active = true; lbl.LeftAnchor.ConstraintEqualTo(this.View.LeftAnchor, 0).Active = true; var p = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); var path = System.IO.Path.Combine(p, "philadelphia.mspk"); MobileScenePackage package = await MobileScenePackage.OpenAsync(path); // Load the package. await package.LoadAsync(); // Show the first scene. var scene = package.Scenes[0]; scene.BaseSurface.BackgroundGrid.IsVisible = false; scene.BaseSurface.NavigationConstraint = NavigationConstraint.None; ARView.Scene = scene; //We'll set the origin of the scene in the middle so we can use that as the tie-point ARView.OriginCamera = new Esri.ArcGISRuntime.Mapping.Camera(39.9579126, -75.1705827, 9.64, 0, 90, 0); ARView.TranslationFactor = 1000; // By increasing the translation factor, the scene appears as if it's at scale 1:1000 //Set the initial location 1.5 meter in front of and .5m above the scene ARView.SetInitialTransformation(TransformationMatrix.Create(0, 0, 0, 1, 0, .5, 1.5)); //Set the clipping distance to only render a circular area around the origin ARView.ClippingDistance = 350; //Listend for double-tap to place ARView.GeoViewDoubleTapped += ArView_GeoViewDoubleTapped; ARView.NorthAlign = false; ARView.RenderPlanes = true; UISwitch sw = new UISwitch() { TranslatesAutoresizingMaskIntoConstraints = false }; sw.ValueChanged += Sw_ValueChanged; View.AddSubview(sw); sw.TopAnchor.ConstraintEqualTo(this.View.TopAnchor, 0).Active = true; sw.RightAnchor.ConstraintEqualTo(this.View.RightAnchor, 0).Active = true; sw.WidthAnchor.ConstraintEqualTo(100); sw.HeightAnchor.ConstraintEqualTo(30); ARView.PlanesDetectedChanged += ARView_PlanesDetectedChanged; _ = ARView.StartTrackingAsync(); }
private async void DisplayScene() { // Hide the help label. Device.BeginInvokeOnMainThread(() => { HelpLabel.IsVisible = false; }); if (_tabletopScene == null) { // Get the downloaded mobile scene package. MobileScenePackage package = await MobileScenePackage.OpenAsync(DataManager.GetDataFolder("7dd2f97bb007466ea939160d0de96a9d", "philadelphia.mspk")); // Load the package. await package.LoadAsync(); // Get the first scene. _tabletopScene = package.Scenes.First(); // Hide the base surface. _tabletopScene.BaseSurface.Opacity = 0; // Enable subsurface navigation. This allows you to look at the scene from below. _tabletopScene.BaseSurface.NavigationConstraint = NavigationConstraint.None; // Set the AR scene to the tabletop scene. MyARSceneView.Scene = _tabletopScene; } // Create a camera at the bottom and center of the scene. // This camera is the point at which the scene is pinned to the real-world surface. Camera originCamera = new Camera(39.95787000283599, -75.16996728256345, 8.813445091247559, 0, 90, 0); // Set the origin camera. MyARSceneView.OriginCamera = originCamera; // The width of the scene content is about 800 meters. double geographicContentWidth = 800; // Set the clipping distance for the scene. MyARSceneView.ClippingDistance = geographicContentWidth / 2; // The desired physical width of the scene is 1 meter. double tableContainerWidth = 1; // Set the translation factor based on the scene content width and desired physical size. MyARSceneView.TranslationFactor = geographicContentWidth / tableContainerWidth; }
private async void DisplayScene() { try { if (_tabletopScene == null) { // Get the downloaded mobile scene package. MobileScenePackage package = await MobileScenePackage.OpenAsync( DataManager.GetDataFolder("7dd2f97bb007466ea939160d0de96a9d", "philadelphia.mspk")); // Load the package. await package.LoadAsync(); // Get the first scene. _tabletopScene = package.Scenes.First(); // Set the clipping distance for the scene. _arSceneView.ClippingDistance = 400; // Enable subsurface navigation. This allows you to look at the scene from below. _tabletopScene.BaseSurface.NavigationConstraint = NavigationConstraint.None; } // Display the scene. _arSceneView.Scene = _tabletopScene; // Create a camera at the bottom and center of the scene. // This camera is the point at which the scene is pinned to the real-world surface. var originCamera = new Esri.ArcGISRuntime.Mapping.Camera(39.95787000283599, -75.16996728256345, 8.813445091247559, 0, 90, 0); // Set the origin camera. _arSceneView.OriginCamera = originCamera; // The width of the scene content is about 800 meters. double geographicContentWidth = 800; // The desired physical width of the scene is 1 meter. double tableContainerWidth = 1; // Set the translation factor based on the scene content width and desired physical size. _arSceneView.TranslationFactor = geographicContentWidth / tableContainerWidth; } catch (System.Exception ex) { new Android.App.AlertDialog.Builder(this).SetMessage("Failed to load scene").SetTitle("Error").Show(); System.Diagnostics.Debug.WriteLine(ex); } }
private async void Initialize() { // Get the path to the scene package. string scenePath = DataManager.GetDataFolder("7dd2f97bb007466ea939160d0de96a9d", "philadelphia.mspk"); try { // Determine if the package can be read directly or needs to be unpacked. if (await MobileScenePackage.IsDirectReadSupportedAsync(scenePath)) { // Open the package. MobileScenePackage package = await MobileScenePackage.OpenAsync(scenePath); // Load the package. await package.LoadAsync(); // Show the first scene. MySceneView.Scene = package.Scenes.First(); } else { // Create a path for the unpacked package. string unpackedPath = scenePath + "unpacked"; // Unpack the package. await MobileScenePackage.UnpackAsync(scenePath, unpackedPath); // Open the package. MobileScenePackage package = await MobileScenePackage.OpenAsync(unpackedPath); // Load the package. await package.LoadAsync(); // Show the first scene. MySceneView.Scene = package.Scenes.First(); } } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Couldn't open scene", e.Message, "OK"); Debug.WriteLine(e); } }
private async void Initialize() { // Get the path to the scene package. string scenePath = DataManager.GetDataFolder("7dd2f97bb007466ea939160d0de96a9d", "philadelphia.mspk"); try { // Open the package. MobileScenePackage package = await MobileScenePackage.OpenAsync(scenePath); // Load the package. await package.LoadAsync(); // Show the first scene. MySceneView.Scene = package.Scenes.First(); } catch (Exception e) { await new MessageDialog(e.Message, "Couldn't open scene").ShowAsync(); Debug.WriteLine(e); } }