예제 #1
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
        private void Sensor_ReadingChanged(OrientationSensor sender, OrientationSensorReadingChangedEventArgs args)
        {
            var c = Camera;

            if (c == null)
            {
                return;
            }

            var l = c.Transformation;
            var q = args.Reading.Quaternion;

            _controller.TransformationMatrix = InitialTransformation + TransformationMatrix.Create(q.X, q.Y, q.Z, q.W, 0, 0, 0);
        }
예제 #5
0
        private async void InitializeScene()
        {
            try {
                //var webSceneUrl = new Uri("https://geoinfo-support.maps.arcgis.com/home/webscene/viewer.html?webscene=47435c44d2d8483d9489218eac5329dd");
                Uri serviceFeatureTable_Uri      = new Uri("https://services.arcgis.com/LeHsdRPbeEIElrVR/arcgis/rest/services/globalSceneTrainees_WFL1/FeatureServer/1");
                ServiceFeatureTable featureTable = new ServiceFeatureTable(serviceFeatureTable_Uri);


                FeatureLayer featureLayer = new FeatureLayer(featureTable)
                {
                    RenderingMode = FeatureRenderingMode.Dynamic
                };

                SimpleLineSymbol mySimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Black, 1);
                SimpleFillSymbol mysimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Colors.Blue, mySimpleLineSymbol);
                SimpleRenderer   mySimpleRenderer   = new SimpleRenderer(mysimpleFillSymbol);

                var scene = new Scene(Basemap.CreateTopographic());
                //scene = new Scene(Basemap.CreateTopographic());
                scene.BaseSurface.BackgroundGrid.IsVisible = false;
                //scene.BaseSurface.ElevationSources.Add(new ArcGISTiledElevationSource(new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")));
                scene.BaseSurface.NavigationConstraint = NavigationConstraint.None;


                RendererSceneProperties myRendererSceneProperties = mySimpleRenderer.SceneProperties;
                myRendererSceneProperties.ExtrusionMode       = ExtrusionMode.AbsoluteHeight;
                myRendererSceneProperties.ExtrusionExpression = "[height]";
                featureLayer.Renderer = mySimpleRenderer;

                scene.OperationalLayers.Add(featureLayer);
                await scene.LoadAsync();

                arSceneView.Scene = scene;
                double widthScene = 1300;
                double widthReal  = 1;

                arSceneView.TranslationFactor = widthScene / widthReal;
                //scene.OperationalLayers.Add(layer);
                arSceneView.ClippingDistance = 800;
                arSceneView.SetInitialTransformation(TransformationMatrix.Create(0, 0, 0, 1, 0, .5, 1.5));
            }
            catch (System.Exception ex)
            {
                await DisplayAlert("Failed to load scene", ex.Message, "OK");

                await Navigation.PopAsync();
            }
        }
예제 #6
0
        private void OnWillRenderScene(ISCNSceneRenderer renderer, SCNScene scene, double timeInSeconds)
        {
            if (_tracking && ARSCNView != null)
            {
                var pov = ARSCNView.PointOfView;
                if (pov != null)
                {
                    var c = Camera;
                    if (c != null)
                    {
                        var q = pov.WorldOrientation;
                        var t = pov.Transform;
                        if (_controller != null)
                        {
                            _controller.TransformationMatrix = InitialTransformation + TransformationMatrix.Create(q.X, q.Y, q.Z, q.W, t.Row3.X, t.Row3.Y, t.Row3.Z);
                        }
                        using (var frame = ARSCNView.Session.CurrentFrame)
                        {
                            var camera = frame?.Camera;
                            if (camera != null)
                            {
                                var intrinsics      = camera.Intrinsics;
                                var imageResolution = camera.ImageResolution;
                                SetFieldOfView(intrinsics.R0C0, intrinsics.R1C1, intrinsics.R0C2, intrinsics.R1C2, (float)imageResolution.Width, (float)imageResolution.Height, GetDeviceOrientation());
                            }
                        }
                    }
                }
            }

            if (IsManualRendering)
            {
                RenderFrame();
            }
            ARSCNViewWillRenderScene?.Invoke(this, new ARSCNViewRenderSceneEventArgs(renderer, scene, timeInSeconds));
        }