Beispiel #1
0
        internal DetectedObject(ARReferenceObject referenceObject) : base()
        {
            this.referenceObject = referenceObject;

            pointCloudVisualization = new DetectedPointCloud(referenceObject.RawFeaturePoints, referenceObject.Center, referenceObject.Extent);
            var scene = SCNScene.FromFile("axes.scn", "art.scnassets", new NSDictionary());

            if (scene != null)
            {
                originVis = new SCNNode();
                foreach (var child in scene.RootNode.ChildNodes)
                {
                    originVis.AddChildNode(child);
                }
            }
            else
            {
                originVis = new SCNNode();
                Console.WriteLine("Error: Coordinate system visualization missing.");
            }

            AddChildNode(pointCloudVisualization);
            Hidden = true;

            Set3DModel(ViewController.Instance?.ModelUrl);
        }
		int Building (float width, float length, float height, float posx, float posy, SCNScene scene, Random rnd) 
		{
			var boxNode = new SCNNode () {
				Geometry = new SCNBox {
					Width = width,
					Height = height,
					Length = length,
					ChamferRadius = 0.02f
				},
				Position = new SCNVector3(posx, height/2.0f, posy)
			};

			scene.RootNode.AddChildNode (boxNode);

			var buildings = new[] { "Content/building1.jpg", "Content/building2.jpg","Content/building3.jpg" };
			var material = new SCNMaterial ();
			material.Diffuse.Contents = UIImage.FromFile (buildings [rnd.Next (buildings.Length)]);
			material.Diffuse.ContentsTransform = SCNMatrix4.Scale (new SCNVector3 (width, height, 1.0f));
			material.Diffuse.WrapS = SCNWrapMode.Repeat;
			material.Diffuse.WrapT = SCNWrapMode.Repeat;
			material.Diffuse.MipFilter = SCNFilterMode.Linear;
			material.Diffuse.MagnificationFilter = SCNFilterMode.Linear;
			material.Specular.Contents = UIColor.Gray;
			material.LocksAmbientWithDiffuse = true;

			boxNode.Geometry.FirstMaterial = material;
			return 0;
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            //let's create a geometric object
            var box = SCNBox.Create(0.1f, 0.1f, 0.1f, 0);

            box.FirstMaterial.Diffuse.ContentColor = UIColor.Green;

            //let's add the box to a SCNNode
            var newNode = new SCNNode();

            newNode.Geometry = box;
            newNode.Position = new SCNVector3(0, 0, -1);

            //Let's create a scene where this node will live in
            var scene = new SCNScene();

            scene.RootNode.Add(newNode);

            //set the scene in the sceneview to display it.
            SceneView.Scene = scene;

            SceneView.DebugOptions = ARKit.ARSCNDebugOptions.ShowFeaturePoints | ARKit.ARSCNDebugOptions.ShowWorldOrigin;


            SceneView.Session.Run(new ARKit.ARWorldTrackingConfiguration()
            {
                PlaneDetection         = ARKit.ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true,
                AutoFocusEnabled       = true,
                WorldAlignment         = ARKit.ARWorldAlignment.Gravity
            }, ARKit.ARSessionRunOptions.ResetTracking);
        }
Beispiel #4
0
 public Character(SCNScene scene) : base()
 {
     this.LoadCharacter();
     this.LoadParticles();
     this.LoadSounds();
     this.LoadAnimations();
 }
Beispiel #5
0
        void RebuildScene(InspectView view, bool recreateScene = true)
        {
            if (recreateScene)
            {
                Scene = new SCNScene();
            }
            else
            {
                currentViewNode?.RemoveFromParentNode();
            }

            currentViewNode = null;

            if (view != null)
            {
                currentViewNode = new InspectViewNode(view).Rebuild(
                    new TreeState(DisplayMode, ShowHiddenViews));

                Scene.Add(currentViewNode);

                Trackball.Target = Scene.RootNode;
            }

            Play(this);
        }
Beispiel #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            gestureManager = new GestureManager(sceneView);
            gestureManager.SingleFingerTouchEvent += gamePlay.GestureManager_SingleFingerTouchEvent;
            gestureManager.TwoFingerTouchEvent    += gamePlay.GestureManager_TwoFingerTouchEvent;

            gamePlay.SceneView = sceneView;

            sceneView.Delegate = this;

            sceneView.ShowsStatistics = true;
            sceneView.DebugOptions    = ARSCNDebugOptions.ShowFeaturePoints;
            sceneView.Session         = gamePlay.Session;

            var scene = new SCNScene();

            _overlayScene = new OverlayScene(sceneView.Bounds.Size);
            _overlayScene.UserInteractionEnabled = false;
            gamePlay.OverlayScene = _overlayScene;

            sceneView.Scene        = scene;
            sceneView.OverlayScene = _overlayScene;
        }
Beispiel #7
0
        public void PlacePlacementNode(SCNScene scene)
        {
            _placementNode          = new PlacementNode();
            _placementNode.Position = _entityNode.Position;

            scene.RootNode.AddChildNode(_placementNode);
        }
Beispiel #8
0
        private SCNNode GetSelectedNode()
        {
            //TODO 5.1 Añadiendo modelos 3D
            switch (Element.SelectedItem)
            {
            case IkeaItem.Cup:
                SCNScene cupScene = SCNScene.FromFile("art.scnassets/cup.scn");
                return(cupScene.RootNode.FindChildNode("cup", false));

            case IkeaItem.Vase:
                SCNScene vaseScene = SCNScene.FromFile("art.scnassets/vase.scn");
                return(vaseScene.RootNode.FindChildNode("vase", false));

            case IkeaItem.Boxing:
                SCNScene boxingScene = SCNScene.FromFile("art.scnassets/boxing.scn");
                return(boxingScene.RootNode.FindChildNode("boxing", false));

            case IkeaItem.Table:
            default:
                SCNScene tableScene = SCNScene.FromFile("art.scnassets/table.scn");
                SCNNode  node       = tableScene.RootNode.FindChildNode("table", false);
                CenterPivot(node);
                return(node);
            }
        }
Beispiel #9
0
 public SceneKitGraphics(SCNScene scene)
 {
     this.scene = scene;
     scene.RootNode.AddChildNode(graphicsNode);
     graphicsNode.AddChildNode(entityNodes[0]);
     graphicsNode.Scale = new SCNVector3(1, -1, 1);
 }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            //ARWorldTrackingSessionConfiguration config;// = new A
            //ARWorldTrackingSessionConfiguration
            ARWorldTrackingConfiguration config = new ARWorldTrackingConfiguration();

            //ARWorldTrackingSessionConfiguration config = new ARWorldTrackingSessionConfiguration{


            //};
            config.PlaneDetection = ARPlaneDetection.Horizontal;
            arSessionConfig       = config;
            arSessionConfig.LightEstimationEnabled = true;

            arSession = new ARSession();

            arSCNView         = new ARSCNView();
            arSCNView.Frame   = View.Bounds;
            arSCNView.Session = arSession;
            arSCNView.AutomaticallyUpdatesLighting = true;
            View.AddSubview(this.arSCNView);
            arSession.Run(this.arSessionConfig, ARSessionRunOptions.RemoveExistingAnchors);



            var scene = SCNScene.FromFile("Models.scnassets/chair/chair.scn");

            SCNNode node = scene.RootNode.ChildNodes[0];


            node.Position = new SCNVector3(0, -1, -1);

            arSCNView.Scene.RootNode.AddNodes(node);
        }
Beispiel #11
0
        public override SCNScene GetInitialScene()
        {
            Prefabs = SCNScene.FromFile("art.scnassets/basic-prefab.scn")
                      .RootNode
                      .ChildNodes
                      .Where(x => x.Name.StartsWith("char"))
                      .ToList();

            foreach (var pf in Prefabs)
            {
                pf.RemoveFromParentNode();
            }

            var shipScene = SCNScene.FromFile("art.scnassets/ship");

            ShipNode = shipScene.RootNode.FindChildNode("ship", false);
            ShipNode.RemoveFromParentNode();

            // place the eb characters on the ship
            var i = 0;

            foreach (var pf in Prefabs.OrderByDescending(x => x.Name))
            {
                var node = pf.Clone();
                node.Scale    = new SCNVector3(1, 1, 0.0001f);
                node.Position = new SCNVector3(0, 1 + (i / 2 * 0.25f), i++);
                ShipNode.AddChildNode(node);
            }

            var scene = base.GetInitialScene();

            scene.RootNode.AddChildNode(ShipNode);

            return(scene);
        }
Beispiel #12
0
        public void LoadScene(string path)
        {
            NSError error;

            this.selectedMaterial = null;

            // Load the specified scene. First create a dictionary containing the options we want.
            var options = new SCNSceneLoadingOptions
            {
                // Create normals if absent.
                CreateNormalsIfAbsent = true,
                // Optimize the rendering by flattening the scene graph when possible. Note that this would prevent you from animating objects independantly.
                FlattenScene = true,
            };

            var scene = SCNScene.FromUrl(new NSUrl($"file://{path}"), options, out error);

            if (scene != null)
            {
                base.Scene = scene;
            }
            else
            {
                Console.WriteLine($"Problem loading scene from: {path}\n{error.LocalizedDescription}");
            }
        }
Beispiel #13
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled       = true,
                LightEstimationEnabled = true,
                WorldAlignment         = ARWorldAlignment.Gravity
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            SCNScene scene = SCNScene.FromFile("moon.dae");
            SCNNode  node  = scene.RootNode;

            node.Position = new SCNVector3(0, 0, -25f);
            sceneView.Scene.RootNode.AddChildNode(node);

            UITapGestureRecognizer tapGestureRecognizer = new UITapGestureRecognizer(HandleTapGesture);

            sceneView.AddGestureRecognizer(tapGestureRecognizer);

            UIPinchGestureRecognizer pinchGestureRecognizer = new UIPinchGestureRecognizer(HandlePinchGesture);

            sceneView.AddGestureRecognizer(pinchGestureRecognizer);

            UIRotationGestureRecognizer rotationGestureRecognizer = new UIRotationGestureRecognizer(HandleRotateGesture);

            sceneView.AddGestureRecognizer(rotationGestureRecognizer);
        }
Beispiel #14
0
        private void ChangeDirection()
        {
            SCNScene arrow = null;

            if (direction == Direction.Right)
            {
                arrow = SCNScene.FromFile("art.scnassets/arrow-right");
            }
            else if (direction == Direction.Left)
            {
                arrow = SCNScene.FromFile("art.scnassets/arrow-left");
            }
            else
            {
                arrow = SCNScene.FromFile("art.scnassets/arrow-up");
            }
            SceneView.Scene = arrow;
            var ship = SceneView.Scene.RootNode.ChildNodes[0];


            ship.Position = new SCNVector3(0f, 0f, -0.5f);
            if (SceneView.PointOfView.ChildNodes.Length > 0)
            {
                var node = SceneView.PointOfView.ChildNodes[0];
                node.RemoveFromParentNode();
            }

            SceneView.PointOfView.AddChildNode(ship);
            ship.Scale = new SCNVector3(0.1f, 0.1f, 0.1f);

            DirectionTimer();
        }
Beispiel #15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Set self as the Scene View's delegate
            SceneView.Delegate = this;

            // Track changes to the session
            SceneView.Session.Delegate = new SessionDelegate();

            // Create a new scene
            var arrowRight = SCNScene.FromFile("art.scnassets/arrow-right");

            ArrowRight = arrowRight.RootNode.FindChildNode("ArrowRight", true);


            var arrowLeft = SCNScene.FromFile("art.scnassets/arrow-left");

            ArrowLeft = arrowLeft.RootNode.FindChildNode("ArrowLeft", true);


            var arrowUp = SCNScene.FromFile("art.scnassets/arrow-up");

            ArrowUp = arrowUp.RootNode.FindChildNode("ArrowUp", true);


            // Set the scene to the view
            SceneView.Scene = arrowRight;


            // Add a tap gesture recognizer
            var tapGesture = new UITapGestureRecognizer(HandleTap);

            View.AddGestureRecognizer(tapGesture);
        }
Beispiel #16
0
        public void PlaceEntityField(SCNScene scene)
        {
            _fieldNode          = new TrackNode();
            _fieldNode.Position = _entityNode.Position + (_entityDirection * _fieldNode.EntityStartPositionOffet);

            scene.RootNode.AddChildNode(_fieldNode);
        }
Beispiel #17
0
        private bool isDisposed = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (this.levelNodeTemplate != null)
                    {
                        this.levelNodeTemplate.Dispose();
                        this.levelNodeTemplate = null;
                    }

                    if (this.levelNodeClone != null)
                    {
                        this.levelNodeClone.Dispose();
                        this.levelNodeClone = null;
                    }

                    if (this.scene != null)
                    {
                        this.scene.Dispose();
                        this.scene = null;
                    }

                    [email protected]();
                }

                isDisposed = true;
            }
        }
        /// <summary>
        /// Loads the model from file
        /// </summary>
        private SCNNode CreateModelFromFile(string modelName, string textureName, string nodeName, SCNVector3 vector)
        {
            try
            {
                var mat = new SCNMaterial();
                mat.Diffuse.Contents        = UIImage.FromFile(textureName);
                mat.LocksAmbientWithDiffuse = true;

                var scene     = SCNScene.FromFile(modelName);
                var geometry  = scene.RootNode.ChildNodes[0].Geometry;
                var modelNode = new SCNNode
                {
                    Position = vector,
                    Geometry = geometry,
                    Scale    = new SCNVector3(0.1f, 0.1f, 0.1f)
                };
                modelNode.Geometry.Materials = new[] { mat };
                return(modelNode);
            }
            catch (Exception ex)
            {
                var e = ex.Message;
            }

            return(null);
        }
Beispiel #19
0
 private void initScene()
 {
     scene           = SCNScene.Create();
     sceneView.Scene = scene;
     sceneView.AutoenablesDefaultLighting = true;
     itemsNodeMap = new Dictionary <Item, SCNNode>();
 }
Beispiel #20
0
        void CreateSwingingTorch()
        {
            var     scnene     = SCNScene.FromFile("torch", GameSimulation.PathForArtResource("level/"), new NSDictionary());
            SCNNode torchSwing = scnene.RootNode.FindChildNode("dummy_master", true);

            RootNode.AddChildNode(torchSwing);
        }
        public void CreateARScene(ARSCNView sceneView)
        {
            var scene = SCNScene.FromFile("art.scnassets/ship");

            sceneView.Scene        = scene;
            sceneView.DebugOptions = ARSCNDebugOptions.ShowWorldOrigin | ARSCNDebugOptions.ShowFeaturePoints;
        }
        public override void ViewDidLoad()
        {
            Title = "ARKit";

            View = sceneView;

            sceneView.ShowsStatistics = true;
            sceneView.AutomaticallyUpdatesLighting = true;

            sceneView.Scene = SCNScene.Create();
            var root = sceneView.Scene.RootNode;

            var cameraNode = SCNNode.Create();

            cameraNode.Camera = SCNCamera.Create();
            root.AddChildNode(cameraNode);

            var lightNode = SCNNode.Create();

            cameraNode.Light = SCNLight.Create();
            root.AddChildNode(lightNode);

            var label = new UILabel(new CGRect(10, 10, 300, 30));

            View.AddSubview(label);
        }
Beispiel #23
0
 public static void EnableEnvironmentMapWithIntensity(this SCNScene self, float intensity, DispatchQueue queue)
 {
     if (self.LightingEnvironment.Contents == null)
     {
         var environmentMap = UIImage.FromFile("Models.scnassets/sharedImages/environment_blur.exr");
         self.LightingEnvironment.ContentImage = environmentMap;
     }
     self.LightingEnvironment.Intensity = intensity;
 }
 /// <summary>
 ///  Note: Always a super-tricky thing in ARKit : must get rid of the managed reference to the Frame object ASAP.
 /// </summary>
 public override void WillRenderScene(ISCNSceneRenderer renderer, SCNScene scene, double timeInSeconds)
 {
     using (var frame = this.sceneView.Session?.CurrentFrame)
     {
         if (frame == null)
         {
             return;
         }
         this.viewModel.ProcessFrame(frame);
     }
 }
Beispiel #25
0
        // Configure AR scene with 3-D object
        public void CreateARScene(ARSCNView sceneView)
        {
            // lLoading the 3-D asset from file, will eventually create assets
            var scene = SCNScene.FromFile("art.scnassets/ship");

            // Attaching the 3-D object to the scene
            sceneView.Scene = scene;
            // This is for debugging purposes
            sceneView.DebugOptions = ARSCNDebugOptions.ShowWorldOrigin |
                                     ARSCNDebugOptions.ShowFeaturePoints;
        }
Beispiel #26
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            TextManager.SetTitle("Shadows");

            TextManager.AddBulletAtLevel("Static", 0);
            TextManager.AddBulletAtLevel("Dynamic", 0);
            TextManager.AddBulletAtLevel("Projected", 0);

            var sceneryHolder = SCNNode.Create();

            sceneryHolder.Name     = "scenery";
            sceneryHolder.Position = new SCNVector3(5, -19, 12);

            GroundNode.AddChildNode(sceneryHolder);

            //add scenery
            var scenery = Utils.SCAddChildNode(sceneryHolder, "scenery", "Scenes.scnassets/banana/level", 130);

            scenery.Position = new SCNVector3(-291.374969f, 1.065581f, -30.519293f);
            scenery.Scale    = new SCNVector3(0.044634f, 0.044634f, 0.044634f);
            scenery.Rotation = new SCNVector4(1, 0, 0, -NMath.PI / 2);

            PalmTree = Utils.SCAddChildNode(GroundNode, "PalmTree", "Scenes.scnassets/palmTree/palm_tree", 15);

            PalmTree.Position = new SCNVector3(3, -1, 7);
            PalmTree.Rotation = new SCNVector4(1, 0, 0, -NMath.PI / 2);

            foreach (var child in PalmTree.ChildNodes)
            {
                child.CastsShadow = false;
            }

            //add a static shadow
            var shadowPlane = SCNNode.FromGeometry(SCNPlane.Create(15, 15));

            shadowPlane.EulerAngles = new SCNVector3(-NMath.PI / 2, (float)(Math.PI / 4) * 0.5f, 0);
            shadowPlane.Position    = new SCNVector3(0.5f, 0.1f, 2);
            shadowPlane.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Images/staticShadow", "tiff"));
            GroundNode.AddChildNode(shadowPlane);
            StaticShadowNode         = shadowPlane;
            StaticShadowNode.Opacity = 0;

            var character = Utils.SCAddChildNode(GroundNode, "explorer", "Scenes.scnassets/explorer/explorer_skinned", 9);

            var animScene    = SCNScene.FromFile("Scenes.scnassets/explorer/idle");
            var animatedNode = animScene.RootNode.FindChildNode("Bip001_Pelvis", true);

            character.AddAnimation(animatedNode.GetAnimation(animatedNode.GetAnimationKeys() [0]), new NSString("idle"));

            character.EulerAngles = new SCNVector3(0, NMath.PI / 2, NMath.PI / 2);
            character.Position    = new SCNVector3(20, 0, 7);
            Character             = character;
        }
        SCNNode CreatePokemonNodeFromFile(string filePath, string nodeName, SCNVector3 vector)
        {
            var pScene  = SCNScene.FromFile(filePath);
            var pokemon = pScene.RootNode.FindChildNode(nodeName, true);

            pokemon.Position    = vector;
            pokemon.PhysicsBody = SCNPhysicsBody.CreateStaticBody();
            pokemon.PhysicsBody.PhysicsShape       = SCNPhysicsShape.Create(pokemon);
            pokemon.PhysicsBody.ContactTestBitMask = (int)BitMaskCategory.Pokeball;
            pokemon.PhysicsBody.CategoryBitMask    = (int)BitMaskCategory.Pokemon;
            return(pokemon);
        }
Beispiel #28
0
        public void LoadModal()
        {
            var scene = SCNScene.FromFile("art.scnassets/ship.scn");

            var wrapperNode = SCNNode.Create();

            foreach (var child in scene.RootNode.ChildNodes)
            {
                wrapperNode.AddChildNode(child);
            }

            this.AddChildNode(wrapperNode);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            ARSCNView SceneView = (View as ARSCNView);

            // Create a new scene
            var scene = SCNScene.FromFile("art.scnassets/Pokemon");

            // Set the scene to the view
            SceneView.Scene = scene;

            SceneView.Session.Delegate = new ARViewSessionDelegate();
        }
Beispiel #30
0
        private void SetupInvironment(SCNScene scene)
        {
            var ambientLight = SCNNode.Create();

            ambientLight.Light = new SCNLight {
                LightType = SCNLightType.Ambient,
                Color     = UIColor.FromWhiteAlpha(0.3f, 1f)
            };
            scene.RootNode.AddChildNode(ambientLight);

            var lightNode = new SCNNode {
                Position = new SCNVector3(0f, 80f, 30f),
                Rotation = new SCNVector4(1f, 0f, 0f, (float)(-Math.PI / 2.8))
            };

            lightNode.Light = new SCNLight {
                LightType      = SCNLightType.Spot,
                Color          = UIColor.FromWhiteAlpha(0.8f, 1f),
                SpotInnerAngle = 0f,
                SpotOuterAngle = 50f,
                ShadowColor    = UIColor.Black,
                ZFar           = 500f,
                ZNear          = 50f
            };

            if (IsHighEndDevice)
            {
                ambientLight.Light.CastsShadow = true;
            }

            scene.RootNode.AddChildNode(lightNode);

            spotLightNode = lightNode;

            var floor = SCNNode.Create();

            floor.Geometry = new SCNFloor();
            floor.Geometry.FirstMaterial.Diffuse.Contents          = ResourceManager.GetResourcePath("wood.png");
            floor.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Scale(2f, 2f, 1f);
            floor.Geometry.FirstMaterial.LocksAmbientWithDiffuse   = true;

            if (IsHighEndDevice)
            {
                ((SCNFloor)floor.Geometry).ReflectionFalloffEnd = 10f;
            }

            var staticBody = SCNPhysicsBody.CreateStaticBody();

            floor.PhysicsBody = staticBody;
            scene.RootNode.AddChildNode(floor);
        }
Beispiel #31
0
        public void InitRotateEntityField(SCNScene scene, SCNVector3 coord1, SCNVector3 coord2)
        {
            entityPositionOnDoubleTouch         = _entityNode.Position;
            entityEulerAnglesOnDoubleTouch      = _entityNode.EulerAngles;
            entityFieldEulerAnglesOnDoubleTouch = _fieldNode.EulerAngles;

            doubleTouchInitPosition = (coord1 + coord2) / 2;
            var diff     = coord2 - coord1;
            var len      = diff.Length;
            var zcomp    = diff.Z;
            var dirAngle = (float)Math.Acos(zcomp / len);

            doubleTouchInitEulerAnglesY = (diff.X > 0) ? dirAngle : (2 * (float)Math.PI - dirAngle);
        }
		void SetupScene ()
		{
			Scene = SCNScene.Create ();

			SetupEnvironment ();
			SetupSceneElements ();
			SetupIntroEnvironment ();
		}
		private void SetupSceneElements (SCNScene scene)
		{
			AddTrainToScene (scene, new SCNVector3 (-5f, 20f, -40f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"), new SCNVector3 (-10f, 15f, 10f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeB.jpg"), new SCNVector3 (-9f, 10f, 10f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeC.jpg"), new SCNVector3 (20f, 15f, -11f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"), new SCNVector3 (25f, 5f, -20f));

			var wallBox = new SCNBox {
				Width = 400f,
				Height = 100f,
				Length = 4f,
				ChamferRadius = 0f
			};

			var wall = SCNNode.FromGeometry (wallBox);
			wall.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("wall.jpg");
			wall.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Mult (
				SCNMatrix4.Scale (24f, 2f, 1f),
				SCNMatrix4.CreateTranslation (0f, 1f, 0f)
			);

			wall.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Repeat;
			wall.Geometry.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Mirror;
			wall.Geometry.FirstMaterial.DoubleSided = false;
			wall.CastsShadow = false;
			wall.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;

			wall.Position = new SCNVector3 (0f, 50f, -92f);
			wall.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			scene.RootNode.AddChildNode (wall);

			wall = wall.Clone ();
			wall.Position = new SCNVector3 (202f, 50f, 0f);
			wall.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI / 2f);
			scene.RootNode.AddChildNode (wall);

			wall = wall.Clone ();
			wall.Position = new SCNVector3 (-202f, 50f, 0f);
			wall.Rotation = new SCNVector4 (0f, 1f, 0f, -(float)Math.PI / 2f);
			scene.RootNode.AddChildNode (wall);

			var planeGeometry = new SCNPlane {
				Width = 400f,
				Height = 100f
			};

			var backWall = SCNNode.FromGeometry (planeGeometry);
			backWall.Geometry.FirstMaterial = wall.Geometry.FirstMaterial;
			backWall.Position = new SCNVector3 (0f, 50f, 200f);
			backWall.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI);
			backWall.CastsShadow = false;
			backWall.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			scene.RootNode.AddChildNode (backWall);

			planeGeometry = new SCNPlane {
				Width = 400f,
				Height = 400f
			};

			var ceilNode = SCNNode.FromGeometry (planeGeometry);
			ceilNode.Position = new SCNVector3 (0f, 100f, 0f);
			ceilNode.Rotation = new SCNVector4 (1f, 0f, 0f, (float)Math.PI / 2f);
			ceilNode.Geometry.FirstMaterial.DoubleSided = false;
			ceilNode.CastsShadow = false;
			ceilNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			scene.RootNode.AddChildNode (ceilNode);

			var rnd = new Random ();
			for (int i = 0; i < 4; i++) {
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeB.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeC.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
			}

			var blockBox = new SCNBox {
				Width = 22f,
				Height = 0.2f,
				Length = 34f,
				ChamferRadius = 0f
			};

			var block = SCNNode.Create ();
			block.Position = new SCNVector3 (20f, 10f, -16f);
			block.Rotation = new SCNVector4 (0f, 1f, 0f, (float)-Math.PI / 4f);
			block.Geometry = blockBox;

			var frontMat = SCNMaterial.Create ();
			frontMat.LocksAmbientWithDiffuse = true;
			frontMat.Diffuse.Contents = ResourceManager.GetResourcePath ("book_front.jpg");
			frontMat.Diffuse.MipFilter = SCNFilterMode.Linear;

			var backMat = SCNMaterial.Create ();
			backMat.LocksAmbientWithDiffuse = true;
			backMat.Diffuse.Contents = ResourceManager.GetResourcePath ("book_back.jpg");
			backMat.Diffuse.MipFilter = SCNFilterMode.Linear;

			block.Geometry.Materials = new SCNMaterial[] { frontMat, backMat };
			block.PhysicsBody = SCNPhysicsBody.CreateDynamicBody ();
			scene.RootNode.AddChildNode (block);

			var rug = SCNNode.Create ();
			rug.Position = new SCNVector3 (0f, 0.01f, 0f);
			rug.Rotation = new SCNVector4 (1f, 0f, 0f, (float)Math.PI / 2f);
			var path = UIBezierPath.FromRoundedRect (new CGRect (-50f, -30f, 100f, 50f), 2.5f);
			path.Flatness = 0.1f;
			rug.Geometry = SCNShape.Create (path, 0.05f);
			rug.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			rug.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("carpet.jpg");
			scene.RootNode.AddChildNode (rug);

			var ball = SCNNode.Create ();
			ball.Position = new SCNVector3 (-5f, 5f, -18f);
			ball.Geometry = SCNSphere.Create (5f);
			ball.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			ball.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("ball.jpg");
			ball.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Scale (2f, 1f, 1f);
			ball.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Mirror;
			ball.PhysicsBody = SCNPhysicsBody.CreateDynamicBody ();
			ball.PhysicsBody.Restitution = 0.9f;
			scene.RootNode.AddChildNode (ball);
		}
		private void SetupInvironment (SCNScene scene)
		{
			var ambientLight = SCNNode.Create ();
			ambientLight.Light = new SCNLight {
				LightType = SCNLightType.Ambient,
				Color = UIColor.FromWhiteAlpha (0.3f, 1f)
			};
			scene.RootNode.AddChildNode (ambientLight);

			var lightNode = new SCNNode {
				Position = new SCNVector3 (0f, 80f, 30f),
				Rotation = new SCNVector4 (1f, 0f, 0f, (float)(-Math.PI / 2.8))
			};

			lightNode.Light = new SCNLight {
				LightType = SCNLightType.Spot,
				Color = UIColor.FromWhiteAlpha (0.8f, 1f),
				SpotInnerAngle = 0f,
				SpotOuterAngle = 50f,
				ShadowColor = UIColor.Black,
				ZFar = 500f,
				ZNear = 50f
			};

			if (IsHighEndDevice)
				ambientLight.Light.CastsShadow = true;

			scene.RootNode.AddChildNode (lightNode);

			spotLightNode = lightNode;

			var floor = SCNNode.Create ();
			floor.Geometry = new SCNFloor ();
			floor.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("wood.png");
			floor.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Scale (2f, 2f, 1f);
			floor.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;

			if (IsHighEndDevice)
				((SCNFloor)floor.Geometry).ReflectionFalloffEnd = 10f;

			var staticBody = SCNPhysicsBody.CreateStaticBody ();
			floor.PhysicsBody = staticBody;
			scene.RootNode.AddChildNode (floor);
		}
		private SCNNode SetupVehicle (SCNScene scene)
		{
			var carScene = SCNScene.FromFile ("rc_car", ResourceManager.ResourceFolder, (NSDictionary)null);
			var chassisNode = carScene.RootNode.FindChildNode ("rccarBody", false);

			chassisNode.Position = new SCNVector3 (0f, 10f, 30f);
			chassisNode.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI);

			var body = SCNPhysicsBody.CreateDynamicBody ();
			body.AllowsResting = false;
			body.Mass = 80f;
			body.Restitution = 0.1f;
			body.Friction = 0.5f;
			body.RollingFriction = 0f;

			chassisNode.PhysicsBody = body;

			var frontCameraNode = SCNNode.Create ();
			frontCameraNode.Position = new SCNVector3 (0f, 3.5f, 2.5f);
			frontCameraNode.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI);
			frontCameraNode.Camera = SCNCamera.Create ();
			frontCameraNode.Camera.XFov = 75f;
			frontCameraNode.Camera.ZFar = 500f;

			chassisNode.AddChildNode (frontCameraNode);

			scene.RootNode.AddChildNode (chassisNode);

			var pipeNode = chassisNode.FindChildNode ("pipe", true);
			reactor = SCNParticleSystem.Create ("reactor", ResourceManager.ResourceFolder);
			reactor.ParticleImage = ResourceManager.GetResourcePath ("spark.png");
			reactorDefaultBirthRate = reactor.BirthRate;
			reactor.BirthRate = 0;
			pipeNode.AddParticleSystem (reactor);

			SCNNode wheel0Node = chassisNode.FindChildNode ("wheelLocator_FL", true);
			SCNNode wheel1Node = chassisNode.FindChildNode ("wheelLocator_FR", true);
			SCNNode wheel2Node = chassisNode.FindChildNode ("wheelLocator_RL", true);
			SCNNode wheel3Node = chassisNode.FindChildNode ("wheelLocator_RR", true);

			var wheel0 = SCNPhysicsVehicleWheel.Create (wheel0Node);
			var wheel1 = SCNPhysicsVehicleWheel.Create (wheel1Node);
			var wheel2 = SCNPhysicsVehicleWheel.Create (wheel2Node);
			var wheel3 = SCNPhysicsVehicleWheel.Create (wheel3Node);

			var min = SCNVector3.Zero;
			var max = SCNVector3.Zero;

			wheel0Node.GetBoundingBox (ref min, ref max);
			float wheelHalfWidth = 0.5f * (max.X - min.X);

			wheel0.ConnectionPosition = SCNVector3.Add (wheel0Node.ConvertPositionToNode (SCNVector3.Zero, chassisNode), new SCNVector3 (wheelHalfWidth, 0f, 0f));
			wheel1.ConnectionPosition = SCNVector3.Subtract (wheel1Node.ConvertPositionToNode (SCNVector3.Zero, chassisNode), new SCNVector3 (wheelHalfWidth, 0f, 0f));
			wheel2.ConnectionPosition = SCNVector3.Add (wheel2Node.ConvertPositionToNode (SCNVector3.Zero, chassisNode), new SCNVector3 (wheelHalfWidth, 0f, 0f));
			wheel3.ConnectionPosition = SCNVector3.Subtract (wheel3Node.ConvertPositionToNode (SCNVector3.Zero, chassisNode), new SCNVector3 (wheelHalfWidth, 0f, 0f));

			var vehicle = SCNPhysicsVehicle.Create (chassisNode.PhysicsBody,
				              new SCNPhysicsVehicleWheel[] { wheel0, wheel1, wheel2, wheel3 });
			scene.PhysicsWorld.AddBehavior (vehicle);
			this.vehicle = vehicle;

			return chassisNode;
		}
		private void AddTrainToScene (SCNScene scene, SCNVector3 position)
		{
			var max = SCNVector3.Zero;
			var min = SCNVector3.Zero;
			var trainScene = SCNScene.FromFile ("train_flat", ResourceManager.ResourceFolder, (NSDictionary)null);

			foreach (var node in trainScene.RootNode.ChildNodes) {
				if (node.Geometry != null) {
					node.Position = new SCNVector3 (
						node.Position.X + position.X,
						node.Position.Y + position.Y,
						node.Position.Z + position.Z
					);

					max = SCNVector3.Zero;
					min = SCNVector3.Zero;

					node.GetBoundingBox (ref min, ref max);

					var body = SCNPhysicsBody.CreateDynamicBody ();
					var boxShape = new SCNBox {
						Width = max.X - min.X,
						Height = max.Y - min.Y,
						Length = max.Z - min.Z,
						ChamferRadius = 0f
					};

					body.PhysicsShape = SCNPhysicsShape.Create (boxShape, (NSDictionary)null);
					node.Pivot = SCNMatrix4.CreateTranslation (0f, -min.Y, 0f);
					node.PhysicsBody = body;
					scene.RootNode.AddChildNode (node);
				}
			}

			var smokeHandle = scene.RootNode.FindChildNode ("Smoke", true);
			var smokeParticleSystem = SCNParticleSystem.Create ("smoke", ResourceManager.ResourceFolder);
			smokeParticleSystem.ParticleImage = ResourceManager.GetResourcePath ("smoke.png");
			smokeHandle.AddParticleSystem (smokeParticleSystem);

			var engineCar = scene.RootNode.FindChildNode ("EngineCar", false);
			var wagon1 = scene.RootNode.FindChildNode ("Wagon1", false);
			var wagon2 = scene.RootNode.FindChildNode ("Wagon2", false);

			max = SCNVector3.Zero;
			min = SCNVector3.Zero;
			engineCar.GetBoundingBox (ref min, ref max);

			var wmax = SCNVector3.Zero;
			var wmin = SCNVector3.Zero;
			wagon1.GetBoundingBox (ref wmin, ref wmax);

			var anchorA = new SCNVector3 (max.X, min.Y, 0f);
			var anchorB = new SCNVector3 (wmin.X, wmin.Y, 0f);

			var joint = SCNPhysicsBallSocketJoint.Create (engineCar.PhysicsBody, anchorA, wagon1.PhysicsBody, anchorB);

			scene.PhysicsWorld.AddBehavior (joint);

			joint = SCNPhysicsBallSocketJoint.Create (wagon1.PhysicsBody,
				new SCNVector3 (wmax.X + 0.1f, wmin.Y, 0f),
				wagon2.PhysicsBody,
				new SCNVector3 (wmin.X - 0.1f, wmin.Y, 0f)
			);

			scene.PhysicsWorld.AddBehavior (joint);
		}
		private void AddWoodenBlockToScene (SCNScene scene, NSString imageName, SCNVector3 position)
		{
			var block = SCNNode.Create ();
			block.Position = position;
			block.Geometry = new SCNBox {
				Width = 5f,
				Height = 5f,
				Length = 5f,
				ChamferRadius = 0f
			};

			block.Geometry.FirstMaterial.Diffuse.Contents = imageName;
			block.Geometry.FirstMaterial.Diffuse.MipFilter = SCNFilterMode.Linear;
			block.PhysicsBody = SCNPhysicsBody.CreateDynamicBody ();
			scene.RootNode.AddChildNode (block);
		}
		public PresentationViewController (string path)
		{
			// Load the presentation settings from the plist file
			var settingsPath = NSBundle.MainBundle.PathForResource (path, "xml");
			SlideSettings = JsonConvert.DeserializeObject<Settings> (File.ReadAllText (settingsPath));

			SlideCache = new Dictionary <string, Slide> ();

			// Create a new empty scene
			Scene = new SCNScene ();

			// Create and add a camera to the scene
			// We create three separate nodes to ease the manipulation of the global position, pitch (ie. orientation around the x axis) and relative position
			// - cameraHandle is used to control the global position in world space
			// - cameraPitch  is used to rotate the position around the x axis
			// - cameraNode   is sometimes manipulated by slides to move the camera relatively to the global position (cameraHandle). But this node is supposed to always be repositioned at (0, 0, 0) in the end of a slide.

			CameraHandle = SCNNode.Create ();
			CameraHandle.Name = "cameraHandle";
			Scene.RootNode.AddChildNode (CameraHandle);

			CameraPitch = SCNNode.Create ();
			CameraPitch.Name = "cameraPitch";
			CameraHandle.AddChildNode (CameraPitch);

			CameraNode = SCNNode.Create ();
			CameraNode.Name = "cameraNode";
			CameraNode.Camera = new SCNCamera ();

			// Set the default field of view to 70 degrees (a relatively strong perspective)
			CameraNode.Camera.XFov = 70.0;
			CameraNode.Camera.YFov = 42.0;
			CameraPitch.AddChildNode (CameraNode);

			// Setup the different lights
			InitLighting ();

			// Create and add a reflective floor to the scene
			var floorMaterial = new SCNMaterial ();
			floorMaterial.Ambient.Contents = NSColor.Black;
			floorMaterial.Diffuse.Contents = new NSImage ("/Library/Desktop Pictures/Circles.jpg");
			floorMaterial.Diffuse.ContentsTransform = SCNMatrix4.CreateFromAxisAngle (new SCNVector3 (0, 0, 1), NMath.PI / 4);
			floorMaterial.Specular.WrapS = 
				floorMaterial.Specular.WrapT = 
					floorMaterial.Diffuse.WrapS = 
						floorMaterial.Diffuse.WrapT = SCNWrapMode.Mirror;

			Floor = SCNFloor.Create ();
			Floor.ReflectionFalloffEnd = 3.0f;
			Floor.FirstMaterial = floorMaterial;

			var floorNode = SCNNode.Create ();
			floorNode.Geometry = Floor;
			Scene.RootNode.AddChildNode (floorNode);

			// Use a shader modifier to support a secondary texture for some slides
			var shaderFile = NSBundle.MainBundle.PathForResource ("Shaders/floor", "shader");
			var surfaceModifier = File.ReadAllText (shaderFile);
			floorMaterial.ShaderModifiers = new SCNShaderModifiers { EntryPointSurface = surfaceModifier };

			// Set the scene to the view
			View = new SCNView (CGRect.Empty);
			((SCNView)View).Scene = Scene;
			((SCNView)View).BackgroundColor = NSColor.Black;

			// Turn on jittering for better anti-aliasing when the scene is still
			((SCNView)View).JitteringEnabled = true;

			// Start the presentation
			GoToSlide (0);
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.
			var scene = new SCNScene ();

			var rnd = new Random ();

			Func<int, int, bool, float> random = (min, max, clamp) => {
				float num = (float)((double)rnd.Next(min, max) * rnd.NextDouble ());
				if (!clamp)
					return num;
				else if (num < 1.0f)
					return 1.0f;
				else
					return num;
			};

			Enumerable.Range (0, 200).Select<int, int> ((i) => Building (
				random (2,5, true),
				random (2,5, true),
				random (2,10, true),
				random (-20, 20, false),
				random (-20, 20, false),
				scene,
				rnd
			)).ToArray ();

			//Lights!
			var lightNode = new SCNNode() {
				Light = new SCNLight (),
				Position = new SCNVector3 (30.0F, 20.0F, 60.0F)
			};
			lightNode.Light.LightType = SCNLightType.Omni;
			scene.RootNode.AddChildNode (lightNode);

			var ambientLightNode = new SCNNode () {
				Light = new SCNLight ()
			};

			ambientLightNode.Light.LightType = SCNLightType.Ambient;
			ambientLightNode.Light.Color = UIColor.DarkGray;
			scene.RootNode.AddChildNode (ambientLightNode);

			//Camera!
			var cameraNode = new SCNNode () { Camera = new SCNCamera () };
			scene.RootNode.AddChildNode (cameraNode);
			cameraNode.Position = new SCNVector3 (0.0F, 10.0F, 20.0F);

			var targetNode = new SCNNode () {
				Position = new SCNVector3 (00.0F, 1.5F, 0.0F)
			};
			scene.RootNode.AddChildNode (targetNode);

			var lc = SCNLookAtConstraint.Create (targetNode);
			cameraNode.Constraints = new[] { lc };

			var scnView = new SCNView(UIScreen.MainScreen.Bounds) {
				Scene = scene,
				AllowsCameraControl = true,
				ShowsStatistics = true,
				BackgroundColor = UIColor.FromRGB (52, 152, 219)
			};

			var floorNode = new SCNNode {
				Geometry = new SCNPlane {
					Height = 40.0F,
					Width = 40.0F
				},
				Position = SCNVector3.Zero
			};

			var pi2 = Math.PI / 2.0;
			floorNode.Orientation = SCNQuaternion.FromAxisAngle (SCNVector3.UnitX, (float)(0.0 - pi2));

			scene.RootNode.AddChildNode (floorNode);

			var material = new SCNMaterial ();
			material.Diffuse.Contents = UIImage.FromFile ("Content/road.jpg");
			material.Diffuse.ContentsTransform = SCNMatrix4.Scale (new SCNVector3 (10.0f, 10.0f, 1.0f));
			material.Diffuse.MinificationFilter = SCNFilterMode.Linear;
			material.Diffuse.MagnificationFilter = SCNFilterMode.Linear;
			material.Diffuse.MipFilter = SCNFilterMode.Linear;
			material.Diffuse.WrapS = SCNWrapMode.Repeat;
			material.Diffuse.WrapT = SCNWrapMode.Repeat;
			material.Specular.Contents = UIColor.Gray;

			floorNode.Geometry.FirstMaterial = material;

			this.View = scnView;
		}