예제 #1
0
        void Initialize()
        {
            BackgroundColor = NSColor.Black;
            var root = scene.RootNode;

            root.AddChildNode(camNode);
            root.AddChildNode(viewsNode);

            var backgroundGeom = SCNBox.Create(10000, 10000, 10, 0);

            backgroundGeom.FirstMaterial = Materials.Plastic(Xyzw(0.8, 1, 0.8, 1), roughness: 0.1).SCNMaterial;
            var backgroundNode = SCNNode.FromGeometry(backgroundGeom);

            backgroundNode.Position = Xyz(0, 0, -5.01).ToSCNVector3();
            viewsNode.AddChildNode(backgroundNode);

            AllowsCameraControl = true;

            scene.Background.ContentImage = new NSImage(
                NSBundle.MainBundle.PathForResource("environment", "jpg"));
            scene.Background.ContentsTransform = SCNMatrix4.CreateRotationX((float)(Math.PI / 2));

            scene.LightingEnvironment.ContentImage      = scene.Background.ContentImage;
            scene.LightingEnvironment.ContentsTransform = SCNMatrix4.CreateRotationX((float)(Math.PI / 2));

            Scene = scene;

            UpdateCamera();
        }
예제 #2
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            SoundManager.PlaySound("miss");

            var imageAnchor = anchor as ARImageAnchor;
            var refSize     = imageAnchor.ReferenceImage.PhysicalSize;
            var box         = new SCNBox
            {
                Width         = refSize.Width * .9f,
                Length        = refSize.Height * .9f,
                Height        = 0.0001f,
                ChamferRadius = 0
            };

            box.FirstMaterial.Diffuse.Contents = UIColor.White.ColorWithAlpha(.95f);

            var pf = Prefabs[i++];

            node.AddChildNode(new SCNNode {
                Geometry = box
            });
            node.AddChildNode(pf);

            pf.Position = SCNVector3.Zero;
        }
예제 #3
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            SoundManager.PlaySound("miss");

            var imageAnchor = anchor as ARImageAnchor;
            var refSize     = imageAnchor.ReferenceImage.PhysicalSize;
            var box         = new SCNBox
            {
                Width         = refSize.Width * 1.75f,
                Length        = refSize.Height * 1.75f,
                Height        = 0.0001f,
                ChamferRadius = 0
            };

            box.FirstMaterial.Diffuse.Contents = ShaderScene.Random();
            box.TileTexture(3);

            var pf = Prefabs[i++];

            node.AddChildNode(new SCNNode {
                Geometry = box
            });
            node.AddChildNode(pf);

            pf.Position = SCNVector3.Zero;
            pf.RunAction(SCNAction.RotateBy(0, 1.5f, 0, 0.01));
        }
예제 #4
0
        private SCNNode GenerateEarth(SCNVector3 position)
        {
            var earth = SCNSphere.Create(EartRadious);

            eartParentNode = new SCNNode
            {
                Position = position,
                Geometry = earth
            };
            earthNode = new SCNNode
            {
                Position = new SCNVector3(distanceEart, 0, 0),
                Geometry = earth
            };
            earthNode.Geometry.FirstMaterial.Diffuse.ContentImage  = UIImage.FromBundle("EartDifuse");
            earthNode.Geometry.FirstMaterial.Specular.ContentImage = UIImage.FromBundle("EarthSpecular");
            earthNode.Geometry.FirstMaterial.Emission.ContentImage = UIImage.FromBundle("EarthEmision");
            earthNode.Geometry.FirstMaterial.Normal.ContentImage   = UIImage.FromBundle("EarthNormal");
            earthNode.Name = "Eart";

            var moon = SCNSphere.Create(radiousMoon);

            moonNode = new SCNNode
            {
                Position = new SCNVector3(distanceMoon, 0, 0),
                Geometry = moon
            };
            moonNode.Geometry.FirstMaterial.Diffuse.ContentImage = UIImage.FromBundle("moon_back");
            moonNode.Name = "Moon";
            eartParentNode.AddChildNode(moonNode);
            earthNode.AddChildNode(moonNode);
            eartParentNode.AddChildNode(earthNode);
            return(eartParentNode);
        }
예제 #5
0
        private SCNNode FocusSquareNode()
        {
            if (focusSquareNode == null)
            {
                /*
                 * The focus square consists of eight Segments as follows, which can be individually animated.
                 *
                 *      s1  s2
                 *      _   _
                 * s3 |     | s4
                 *
                 * s5 |     | s6
                 *      -   -
                 *      s7  s8
                 */

                var sl = 0.5f;                      // segment length
                var c  = FocusSquareThickness / 2f; // correction to align lines perfectly

                var s1 = new FocusSquareSegment("s1", Corner.TopLeft, Alignment.Horizontal);
                var s2 = new FocusSquareSegment("s2", Corner.TopRight, Alignment.Horizontal);
                var s3 = new FocusSquareSegment("s3", Corner.TopLeft, Alignment.Vertical);
                var s4 = new FocusSquareSegment("s4", Corner.TopRight, Alignment.Vertical);
                var s5 = new FocusSquareSegment("s5", Corner.BottomLeft, Alignment.Vertical);
                var s6 = new FocusSquareSegment("s6", Corner.BottomRight, Alignment.Vertical);
                var s7 = new FocusSquareSegment("s7", Corner.BottomLeft, Alignment.Horizontal);
                var s8 = new FocusSquareSegment("s8", Corner.BottomRight, Alignment.Horizontal);

                s1.Position = s1.Position.Add(new SCNVector3(-(sl / 2 - c), -(sl - c), 0));
                s2.Position = s2.Position.Add(new SCNVector3(sl / 2 - c, -(sl - c), 0));
                s3.Position = s3.Position.Add(new SCNVector3(-sl, -sl / 2, 0));
                s4.Position = s4.Position.Add(new SCNVector3(sl, -sl / 2, 0));
                s5.Position = s5.Position.Add(new SCNVector3(-sl, sl / 2, 0));
                s6.Position = s6.Position.Add(new SCNVector3(sl, sl / 2, 0));
                s7.Position = s7.Position.Add(new SCNVector3(-(sl / 2 - c), sl - c, 0));
                s8.Position = s8.Position.Add(new SCNVector3(sl / 2 - c, sl - c, 0));

                var planeNode = new SCNNode();
                planeNode.EulerAngles = new SCNVector3((float)(Math.PI / 2), planeNode.EulerAngles.Y, planeNode.EulerAngles.Z);
                planeNode.SetUniformScale(FocusSquareSize * ScaleForClosedSquare);

                planeNode.AddChildNode(s1);
                planeNode.AddChildNode(s2);
                planeNode.AddChildNode(s3);
                planeNode.AddChildNode(s4);
                planeNode.AddChildNode(s5);
                planeNode.AddChildNode(s6);
                planeNode.AddChildNode(s7);
                planeNode.AddChildNode(s8);
                planeNode.AddChildNode(FillPlane);
                segments = new FocusSquareSegment[] { s1, s2, s3, s4, s5, s6, s7, s8 };

                IsOpen = false;

                // Always render focus square on top
                planeNode.RenderOnTop();
                focusSquareNode = planeNode;
            }
            return(focusSquareNode);
        }
예제 #6
0
        private SCNNode CreateTransparentTrackNode()
        {
            var transparentTrackNode = new SCNNode();

            var geometryLength = new SCNCylinder()
            {
                Height = _fieldLength, Radius = LINE_RADIUS
            };
            var geometryWidth = new SCNCylinder()
            {
                Height = _fieldWidth, Radius = LINE_RADIUS
            };

            var lengthNode1 = new SCNNode();

            lengthNode1.Geometry = geometryLength;
            lengthNode1.Geometry.Materials.First().Diffuse.Contents = TRANSPARENTTRACK_COLOR;
            lengthNode1.EulerAngles = new SCNVector3(-1 * (float)Math.PI / 2, (float)Math.PI / 2, 0);
            lengthNode1.Position    = new SCNVector3(0f, 0f, _fieldWidth / 2);

            transparentTrackNode.AddChildNode(lengthNode1);

            var lengthNode2 = new SCNNode();

            lengthNode2.Geometry = geometryLength;
            lengthNode2.Geometry.Materials.First().Diffuse.Contents = TRANSPARENTTRACK_COLOR;
            lengthNode2.EulerAngles = new SCNVector3(-1 * (float)Math.PI / 2, (float)Math.PI / 2, 0);
            lengthNode2.Position    = new SCNVector3(0f, 0f, -1f * _fieldWidth / 2);

            transparentTrackNode.AddChildNode(lengthNode2);

            var widthNode1 = new SCNNode();

            widthNode1.Geometry = geometryWidth;
            widthNode1.Geometry.Materials.First().Diffuse.Contents = TRANSPARENTTRACK_COLOR;
            widthNode1.EulerAngles = new SCNVector3(-1 * (float)Math.PI / 2, 0, 0);
            widthNode1.Position    = new SCNVector3(_fieldLength / 2, 0f, 0);

            transparentTrackNode.AddChildNode(widthNode1);

            var widthNode2 = new SCNNode();

            widthNode2.Geometry = geometryWidth;
            widthNode2.Geometry.Materials.First().Diffuse.Contents = TRANSPARENTTRACK_COLOR;
            widthNode2.EulerAngles = new SCNVector3(-1 * (float)Math.PI / 2, 0, 0);
            widthNode2.Position    = new SCNVector3(-1 * _fieldLength / 2, 0f, 0);

            transparentTrackNode.AddChildNode(widthNode2);

            return(transparentTrackNode);
        }
        private void OnFoundThing(SCNNode node, ARObjectAnchor anchor)
        {
            adding = true;
            var size = anchor.ReferenceObject.Extent;
            var name = ReplacementNameFor(anchor.Name.Split('-')[0]);

            if (_alreadySeen.Contains(name))
            {
                return;
            }

            _alreadySeen.Add(name);

            if (!_contentFor.TryGetValue(name, out var content))
            {
                SoundManager.PlaySound("spooky");
                adding = false;
                return;
            }

            NodeLookup[node] = node;

            var panel = Panels[content.Logo];

            panel.Position = new SCNVector3(0, content.Offset, -.05f);
            node.AddChildNode(panel);

            var refSize    = anchor.ReferenceObject.Extent;
            var invisiNode = new SCNNode
            {
                Geometry = new SCNBox {
                    Height = refSize.Y, Width = refSize.X, Length = refSize.Z
                },
                Position = new SCNVector3(0, .05f, 0)
            };

            invisiNode.Geometry.FirstMaterial.Diffuse.Contents = UIColor.FromWhiteAlpha(1.0f, 0.05f);

            node.AddChildNode(invisiNode);
            NodeLookup[invisiNode] = node;
            node.Name = name;

            foreach (var sound in _contentFor.Values.Select(x => x.BGM))
            {
                SoundManager.PauseSound(sound);
            }

            SoundManager.PlaySound(content.BGM, false);
            adding = false;
        }
예제 #8
0
        public static SCNNode CreateCrossNode(float size, string style, bool horizontal = true, float opacity = 1f)
        {
            // Create a size x size m plane and put a grid texture onto it.
            var planeDimention = size;

            var image = UIImage.FromBundle(style);

            var planeNode = SCNNode.FromGeometry(CreateSquarePlane(planeDimention, image));
            var material  = planeNode.Geometry.Materials[0];

            material.Ambient.Contents  = UIColor.Black;
            material.LightingModelName = SCNLightingModel.Constant;

            if (horizontal)
            {
                planeNode.EulerAngles = new SCNVector3((float)Math.PI / 2f, 0, (float)Math.PI);
            }
            else
            {
                planeNode.Constraints = new SCNConstraint[] { new SCNBillboardConstraint() };
            }

            // Assemble cross
            var cross = new SCNNode()
            {
                Name = "Cross"
            };

            cross.AddChildNode(planeNode);
            cross.Opacity = opacity;

            // Return results
            return(cross);
        }
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Set the slide's title and subtitle and add some text
			TextManager.SetTitle ("Animations");
			TextManager.SetSubtitle ("Implicit animations");

			TextManager.AddCode ("#// Begin a transaction \n"
			+ "#SCNTransaction#.Begin (); \n"
			+ "#SCNTransaction#.AnimationDuration = 2.0f; \n\n"
			+ "// Change properties \n"
			+ "aNode.#Opacity# = 1.0f; \n"
			+ "aNode.#Rotation# = \n"
			+ " new SCNVector4 (0, 1, 0, NMath.PI * 4); \n\n"
			+ "// Commit the transaction \n"
			+ "SCNTransaction.#Commit ()#;#");

			// A simple torus that we will animate to illustrate the code
			AnimatedNode = SCNNode.Create ();
			AnimatedNode.Position = new SCNVector3 (10, 7, 0);

			// Use an extra node that we can tilt it and cumulate that with the animation
			var torusNode = SCNNode.Create ();
			torusNode.Geometry = SCNTorus.Create (4.0f, 1.5f);
			torusNode.Rotation = new SCNVector4 (1, 0, 0, -(float)(Math.PI * 0.7f));
			torusNode.Geometry.FirstMaterial.Diffuse.Contents = NSColor.Red;
			torusNode.Geometry.FirstMaterial.Specular.Contents = NSColor.White;
			torusNode.Geometry.FirstMaterial.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("SharedTextures/envmap", "jpg"));
			torusNode.Geometry.FirstMaterial.FresnelExponent = 0.7f;

			AnimatedNode.AddChildNode (torusNode);
			ContentNode.AddChildNode (AnimatedNode);
		}
예제 #10
0
        void PlaceAnchorNode(SCNNode node, ARPlaneAnchor anchor)
        {
            var plane = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z);

            plane.FirstMaterial.Diffuse.Contents = UIColor.LightGray;
            var planeNode = SCNNode.FromGeometry(plane);

            //Locate the plane at the position of the anchor
            planeNode.Position = new SCNVector3(anchor.Extent.X, 0.0f, anchor.Extent.Z);
            //Rotate it to lie flat
            planeNode.Transform = SCNMatrix4.CreateRotationX((float)(Math.PI / 2.0));
            node.AddChildNode(planeNode);

            //Mark the anchor with a small red box
            var box = new SCNBox {
                Height = 0.18f, Width = 0.18f, Length = 0.18f
            };

            box.FirstMaterial.Diffuse.ContentColor = UIColor.Red;
            var anchorNode = new SCNNode {
                Position = new SCNVector3(0, 0, 0), Geometry = box
            };

            planeNode.AddChildNode(anchorNode);
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
        public LocationAnnotationNode(CLLocation location, string image, string type, string name, string line1, string line2, double distance = 0)
            : base(location)
        {
            distance = 1;

            AnnotationNode = new SCNNode();
            AddChildNode(AnnotationNode);

            var bilboardConstraint = new SCNBillboardConstraint
            {
                FreeAxes = SCNBillboardAxis.Y
            };

            Constraints = new[] { bilboardConstraint };

            var content   = CreateContentNode(name, line1, line2, new CGSize(4, 4), 8);
            var header    = CreateHeaderNode(type, image, content.Size(), new CGSize(8, 12));
            var separator = CreateBackgroundPlaneNode(new CGSize(Math.Max(content.Width(), header.Width()), 1), UIColor.LightGray.ColorWithAlpha(0.5F), 0);
            var rootNode  = CreateBackgroundPlaneNode(new CGSize(Math.Max(content.Width(), header.Width()), content.Height() + header.Height() + separator.Height()), UIColor.White, 0);

            AnnotationNode.AddChildNode(rootNode);
            rootNode.AddChildNode(header);
            header.AlignTopTo(rootNode, 0);
            header.AlignCenterHorizontallyWith(rootNode, 0);

            rootNode.AddChildNode(separator);
            rootNode.AddChildNode(content);
            separator.AlignTopTo(rootNode, -header.Height());
            content.AlignTopTo(rootNode, -(header.Height() + separator.Height()));
            content.AlignLeftTo(rootNode, 0);
            rootNode.Scale = new SCNVector3(rootNode.Scale.X * 0.01F, rootNode.Scale.Y * 0.01F, rootNode.Scale.Z * 0.01F);
            Opacity        = 0.8F;
        }
예제 #14
0
        private void AddPlanet(SCNVector3 sunPosition, float radious, string diffuse, string specular, string emission, string normal, float xPosition, double selfRotation, double sunRotation)
        {
            SCNNode parent = new SCNNode();

            parent.Position = sunPosition;
            sceneView.Scene.RootNode.AddChildNode(parent);

            SCNNode planet = new SCNNode();

            planet.Geometry = SCNSphere.Create(radious);
            planet.Geometry.FirstMaterial.Diffuse.Contents  = string.IsNullOrWhiteSpace(diffuse) ? null : new UIImage(diffuse);
            planet.Geometry.FirstMaterial.Specular.Contents = string.IsNullOrWhiteSpace(specular) ? null : new UIImage(specular);
            planet.Geometry.FirstMaterial.Emission.Contents = string.IsNullOrWhiteSpace(emission) ? null : new UIImage(emission);
            planet.Geometry.FirstMaterial.Normal.Contents   = string.IsNullOrWhiteSpace(normal) ? null : new UIImage(normal);
            planet.Position = new SCNVector3(xPosition, 0, 0);

            //TODO 3.2 Movimientos
            SCNAction selfAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360), 0, selfRotation);
            SCNAction selfForever = SCNAction.RepeatActionForever(selfAction);

            planet.RunAction(selfForever);

            SCNAction sunAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360), 0, sunRotation);
            SCNAction sunForever = SCNAction.RepeatActionForever(sunAction);

            parent.RunAction(sunForever);

            parent.AddChildNode(planet);
        }
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Set the slide's title and subtitle and add some text
			TextManager.SetTitle ("Animations");
			TextManager.SetSubtitle ("Explicit animations");

			TextManager.AddCode ("#// Create an animation \n"
			+ "animation = #CABasicAnimation#.FromKeyPath (\"rotation\"); \n\n"
			+ "// Configure the animation \n"
			+ "animation.#Duration# = 2.0f; \n"
			+ "animation.#To# = NSValue.FromVector (new SCNVector4 (0, 1, 0, NMath.PI * 2)); \n"
			+ "animation.#RepeatCount# = float.MaxValue; \n\n"
			+ "// Play the animation \n"
			+ "aNode.#AddAnimation #(animation, \"myAnimation\");#");

			// A simple torus that we will animate to illustrate the code
			AnimatedNode = SCNNode.Create ();
			AnimatedNode.Position = new SCNVector3 (9, 5.7f, 16);

			// Use an extra node that we can tilt it and cumulate that with the animation
			var torusNode = SCNNode.Create ();
			torusNode.Geometry = SCNTorus.Create (4.0f, 1.5f);
			torusNode.Rotation = new SCNVector4 (1, 0, 0, -(float)(Math.PI * 0.5f));
			torusNode.Geometry.FirstMaterial.Diffuse.Contents = NSColor.Cyan;
			torusNode.Geometry.FirstMaterial.Specular.Contents = NSColor.White;
			torusNode.Geometry.FirstMaterial.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("SharedTextures/envmap", "jpg"));
			torusNode.Geometry.FirstMaterial.FresnelExponent = 0.7f;

			AnimatedNode.AddChildNode (torusNode);
			ContentNode.AddChildNode (AnimatedNode);
		}
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Set the slide's title and subtitle and add some text
            TextManager.SetTitle("Animations");
            TextManager.SetSubtitle("Implicit animations");

            TextManager.AddCode("#// Begin a transaction \n"
                                + "#SCNTransaction#.Begin (); \n"
                                + "#SCNTransaction#.AnimationDuration = 2.0f; \n\n"
                                + "// Change properties \n"
                                + "aNode.#Opacity# = 1.0f; \n"
                                + "aNode.#Rotation# = \n"
                                + " new SCNVector4 (0, 1, 0, NMath.PI * 4); \n\n"
                                + "// Commit the transaction \n"
                                + "SCNTransaction.#Commit ()#;#");

            // A simple torus that we will animate to illustrate the code
            AnimatedNode          = SCNNode.Create();
            AnimatedNode.Position = new SCNVector3(10, 7, 0);

            // Use an extra node that we can tilt it and cumulate that with the animation
            var torusNode = SCNNode.Create();

            torusNode.Geometry = SCNTorus.Create(4.0f, 1.5f);
            torusNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI * 0.7f));
            torusNode.Geometry.FirstMaterial.Diffuse.Contents    = NSColor.Red;
            torusNode.Geometry.FirstMaterial.Specular.Contents   = NSColor.White;
            torusNode.Geometry.FirstMaterial.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg"));
            torusNode.Geometry.FirstMaterial.FresnelExponent     = 0.7f;

            AnimatedNode.AddChildNode(torusNode);
            ContentNode.AddChildNode(AnimatedNode);
        }
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Set the slide's title and subtitle and add some text
            TextManager.SetTitle("Animations");
            TextManager.SetSubtitle("Explicit animations");

            TextManager.AddCode("#// Create an animation \n"
                                + "animation = #CABasicAnimation#.FromKeyPath (\"rotation\"); \n\n"
                                + "// Configure the animation \n"
                                + "animation.#Duration# = 2.0f; \n"
                                + "animation.#To# = NSValue.FromVector (new SCNVector4 (0, 1, 0, NMath.PI * 2)); \n"
                                + "animation.#RepeatCount# = float.MaxValue; \n\n"
                                + "// Play the animation \n"
                                + "aNode.#AddAnimation #(animation, \"myAnimation\");#");

            // A simple torus that we will animate to illustrate the code
            AnimatedNode          = SCNNode.Create();
            AnimatedNode.Position = new SCNVector3(9, 5.7f, 16);

            // Use an extra node that we can tilt it and cumulate that with the animation
            var torusNode = SCNNode.Create();

            torusNode.Geometry = SCNTorus.Create(4.0f, 1.5f);
            torusNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI * 0.5f));
            torusNode.Geometry.FirstMaterial.Diffuse.Contents    = NSColor.Red;
            torusNode.Geometry.FirstMaterial.Specular.Contents   = NSColor.White;
            torusNode.Geometry.FirstMaterial.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg"));
            torusNode.Geometry.FirstMaterial.FresnelExponent     = 0.7f;

            AnimatedNode.AddChildNode(torusNode);
            ContentNode.AddChildNode(AnimatedNode);
        }
예제 #18
0
        private void ShowPatientDetails(ARReferenceImage detectedImage, SCNNode node)
        {
            // Highlight the QR Code?
            var width     = detectedImage.PhysicalSize.Width;
            var length    = detectedImage.PhysicalSize.Height;
            var planeNode = new PlaneNode(0, width, length, new SCNVector3(0, 0, 0), "");

            planeNode.Opacity = 1f;
            float angle = (float)(-Math.PI / 2);

            planeNode.EulerAngles = new SCNVector3(angle, 0, 0);
            //node.AddChildNode(planeNode);

            // Get and Show information panels
            foreach (var informationPanelNode in GetPatientInformationPanels())
            {
                var waitAction     = SCNAction.Wait(0.1 * informationPanelNode.Number);
                var fadeInAction   = SCNAction.FadeIn(1);
                var actionSequence = SCNAction.Sequence(new[] { waitAction, fadeInAction });

                // Not sure I can run actions before adding. May have to add, then run.
                informationPanelNode.RunAction(actionSequence);

                informationPanelNode.EulerAngles = new SCNVector3(angle, 0, 0);

                node.AddChildNode(informationPanelNode);
            }
        }
예제 #19
0
 public SceneKitGraphics(SCNScene scene)
 {
     this.scene = scene;
     scene.RootNode.AddChildNode(graphicsNode);
     graphicsNode.AddChildNode(entityNodes[0]);
     graphicsNode.Scale = new SCNVector3(1, -1, 1);
 }
        public void PositionScene(ARSCNView sceneView, string arLaunchType)
        {
            var arConfiguration = new ARWorldTrackingConfiguration
            {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            sceneView.Session.Run(arConfiguration, ARSessionRunOptions.ResetTracking);

            var sceneShipNode = sceneView.Scene.RootNode.FindChildNode("ship", true);

            sceneShipNode.Position = new SCNVector3(2f, -2f, -9f);

            var animationCycle  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, 6f, 0, 5));
            var animationCrash  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI, (float)Math.PI, (float)1));
            var animationNormal = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 0, 1));
            var animationRotate = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 2, 1));


            var scenePivotNode = new SCNNode {
                Position = new SCNVector3(0.0f, 2.0f, 0.0f)
            };

            scenePivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -2, 0, 10)));

            sceneShipNode.RemoveFromParentNode();
            scenePivotNode.AddChildNode(sceneShipNode);

            sceneView.Scene.RootNode.AddChildNode(scenePivotNode);

            sceneShipNode.Scale    = new SCNVector3(0.1f, 0.1f, 0.1f);
            sceneShipNode.Position = new SCNVector3(2f, -2f, -3f);


            switch (arLaunchType)
            {
            case "Rotate Fly":
                sceneShipNode.RunAction(animationRotate);
                break;

            case "Crash Fly":
                sceneShipNode.RunAction(animationCrash);
                break;

            case "Cycle Fly":
                sceneShipNode.RunAction(animationCycle);
                break;

            case "Normal Fly":
                sceneShipNode.RunAction(animationNormal);
                break;

            default:
                scenePivotNode.RemoveAllActions();
                scenePivotNode.RunAction(SCNAction.Unhide());
                break;
            }
        }
예제 #21
0
        internal static SCNNode Load3DModel(NSUrl url)
        {
            var scene = SCNScene.FromUrl(url, new NSDictionary(), out var err);

            if (scene == null)
            {
                Console.WriteLine($"Error: failed to load 3D model from file {url}.");
                if (err != null)
                {
                    Console.WriteLine(err.ToString());
                }
                return(null);
            }

            var node = new SCNNode();

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

            // If there are no light sources in the model, add some
            var lightNodes = node.ChildNodes.Where(child => child.Light != null);

            if (lightNodes.Count() == 0)
            {
                var ambientLight = new SCNLight
                {
                    LightType = SCNLightType.Ambient,
                    Intensity = 100
                };
                var ambientLightNode = new SCNNode();
                ambientLightNode.Light = ambientLight;
                node.AddChildNode(ambientLightNode);

                var directionLight = new SCNLight
                {
                    LightType = SCNLightType.Directional,
                    Intensity = 500
                };
                var directionalLightNode = new SCNNode();
                directionalLightNode.Light = directionLight;
                node.AddChildNode(directionalLightNode);
            }
            return(node);
        }
예제 #22
0
 public void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (!string.IsNullOrEmpty(anchor.Name) &&
         anchor.Name.StartsWith("panda", StringComparison.InvariantCulture))
     {
         node.AddChildNode(this.LoadRedPandaModel());
     }
 }
예제 #23
0
        private void addPlane(SCNNode node, ARPlaneAnchor anchor)
        {
            Plane plane = new Plane(anchor);

            viewController.Planes.Add(anchor, plane);

            node.AddChildNode(plane);
        }
        private void SetupScenegraph()
        {
            eyeLNode = CreateEyeNode();
            eyeRNode = CreateEyeNode();

            SceneView.Scene.RootNode.AddChildNode(faceNode);
            SceneView.Scene.RootNode.AddChildNode(virtualPhoneNode);
            virtualPhoneNode.AddChildNode(virtualScreenNode);
            faceNode.AddChildNode(eyeLNode);
            faceNode.AddChildNode(eyeRNode);
            eyeLNode.AddChildNode(lookAtTargetEyeLNode);
            eyeRNode.AddChildNode(lookAtTargetEyeRNode);

            // Set LookAtTargetEye at 2 meters away from the center of eyeballs to create segment vector
            lookAtTargetEyeLNode.Position = new SCNVector3(lookAtTargetEyeLNode.Position.X, lookAtTargetEyeLNode.Position.Y, 2);

            lookAtTargetEyeRNode.Position = new SCNVector3(lookAtTargetEyeRNode.Position.X, lookAtTargetEyeRNode.Position.Y, 2);
        }
예제 #25
0
 public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
 {
     if (anchor is ARPlaneAnchor planeAnchor)
     {
         var planeNode = new PlaneNode(planeAnchor);
         node.AddChildNode(planeNode);
         this.planeNodes.Add(anchor.Identifier, planeNode);
     }
 }
예제 #26
0
        void SetupCamera()
        {
            SCNNode     pov      = GameView.PointOfView;
            const float altitude = 1f;
            const float distance = 10f;

            cameraYHandle = SCNNode.Create();
            cameraXHandle = SCNNode.Create();

            cameraYHandle.Position = new SCNVector3(0f, altitude, 0f);
            cameraYHandle.AddChildNode(cameraXHandle);
            GameView.Scene.RootNode.AddChildNode(cameraYHandle);

            pov.EulerAngles = new SCNVector3(0f, 0f, 0f);
            pov.Position    = new SCNVector3(0f, 0f, distance);

            cameraYHandle.Rotation = new SCNVector4(0f, 1f, 0f, (float)Math.PI / 2f + (float)Math.PI / 4f * 3f);
            cameraXHandle.Rotation = new SCNVector4(1f, 0f, 0f, -(float)Math.PI / 4f * 0.125f);
            cameraXHandle.AddChildNode(pov);

            // Animate camera on launch and prevent the user from manipulating the camera until the end of the animation
            lockCamera = true;
            SCNTransaction.Begin();
            SCNTransaction.SetCompletionBlock(() => {
                lockCamera = false;
            });

            var cameraYAnimation = CABasicAnimation.FromKeyPath("rotation.w");

            cameraYAnimation.From           = NSNumber.FromDouble(Math.PI * 2 - cameraYHandle.Rotation.W);
            cameraYAnimation.To             = NSNumber.FromDouble(0.0);
            cameraYAnimation.Additive       = true;
            cameraYAnimation.BeginTime      = CAAnimation.CurrentMediaTime() + 3;
            cameraYAnimation.FillMode       = CAFillMode.Both;
            cameraYAnimation.Duration       = 5.0;
            cameraYAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            cameraYHandle.AddAnimation(cameraYAnimation, null);

            var cameraXAnimation = CABasicAnimation.FromKeyPath("rotation.w");

            cameraXAnimation.From           = NSNumber.FromDouble(-Math.PI / 2 + cameraXHandle.Rotation.W);
            cameraXAnimation.To             = NSNumber.FromDouble(0.0);
            cameraXAnimation.Additive       = true;
            cameraXAnimation.FillMode       = CAFillMode.Both;
            cameraXAnimation.Duration       = 5.0;
            cameraXAnimation.BeginTime      = CAAnimation.CurrentMediaTime() + 3;
            cameraXAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            cameraXHandle.AddAnimation(cameraXAnimation, null);

            SCNTransaction.Commit();

            var lookAtConstraint = SCNLookAtConstraint.Create(Character.Node.FindChildNode("Bip001_Head", true));

            lookAtConstraint.InfluenceFactor = 0;
            pov.Constraints = new SCNConstraint[] { lookAtConstraint };
        }
예제 #27
0
        public void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            var planeAnchor = anchor as ARPlaneAnchor;

            if (planeAnchor == null)
            {
                return;
            }

            Console.WriteLine("didAddNode");

            var text = SCNText.Create("This is a good spot", 0);

            text.Font = UIFont.FromName("Arial", 1);
            if (text.FirstMaterial != null)
            {
                text.FirstMaterial.Diffuse.Contents = UIColor.Green;
            }

            var textNode = SCNNode.FromGeometry(text);

            textNode.Position = new SCNVector3(-0.3f, -0.55f, 0.25f);
            textNode.Scale    = new SCNVector3(0.075f, 0.1f, 0.5f);

            var plane     = SCNPlane.Create(new nfloat(planeAnchor.Extent.X), new nfloat(planeAnchor.Extent.Z));
            var planeNode = SCNNode.FromGeometry(plane);

            planeNode.Position = new SCNVector3(planeAnchor.Center.X, 0f, planeAnchor.Center.Z);

            var txtAngles = textNode.EulerAngles;

            txtAngles.X          = (float)(-1f * (Math.PI / 2f));
            textNode.EulerAngles = txtAngles;
            var planeAngles = planeNode.EulerAngles;

            planeAngles.X         = (float)(-1f * (Math.PI / 2f));
            planeNode.EulerAngles = planeAngles;

            planeNode.Opacity = 0.25f;

            node.AddChildNode(planeNode);
            node.AddChildNode(textNode);
        }
예제 #28
0
            public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
            {
                if (anchor is ARImageAnchor imageAnchor)
                {
                    var box = new SCNBox();

                    nfloat width  = imageAnchor.ReferenceImage.PhysicalSize.Width;
                    nfloat height = imageAnchor.ReferenceImage.PhysicalSize.Height;

                    box.Width  = width;
                    box.Height = height;
                    box.Length = (System.nfloat) 0.1;
                    box.FirstMaterial.Diffuse.Contents = UIColor.Orange;

                    SCNText text = SCNText.Create("Enter Here", (System.nfloat) 0.1);
                    text.Font     = UIFont.SystemFontOfSize(1);
                    text.Flatness = (System.nfloat) 0.05;
                    text.FirstMaterial.Diffuse.Contents = UIColor.Red;


                    var textNode = new SCNNode
                    {
                        Geometry = text,
                    };



                    textNode.Scale       = new SCNVector3((float)0.5, (float)0.5, (float)0.5);
                    textNode.EulerAngles = new SCNVector3((float)(-1.57), 0, 0);

                    textNode.Position = new SCNVector3
                    {
                        X = (float)(imageAnchor.Transform.Column3.X + 2),
                        Y = imageAnchor.Transform.Column3.Y - 2,
                        Z = imageAnchor.Transform.Column3.Z
                    };



                    var boxNode = new SCNNode
                    {
                        Geometry = box,

                        Position = new SCNVector3 {
                            X = -imageAnchor.Transform.Column3.X / 2,
                            Y = -imageAnchor.Transform.Column3.Y,
                            Z = imageAnchor.Transform.Column3.Z
                        }
                    };

                    node.AddChildNode(textNode);
                    //node.AddChildNode(boxNode);
                }
            }
예제 #29
0
        void SetupCollisionNodes(SCNNode node)
        {
            if (node.Geometry != null)
            {
                Console.WriteLine(node.Name);
                node.PhysicsBody = SCNPhysicsBody.CreateStaticBody();
                node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Collision;

                var options = new SCNPhysicsShapeOptions {
                    ShapeType = SCNPhysicsShapeType.ConcavePolyhedron
                };
                node.PhysicsBody.PhysicsShape = SCNPhysicsShape.Create(node, options);

                // Get grass area to play the right sound steps
                if (node.Geometry.FirstMaterial.Name == "grass-area")
                {
                    if (grassArea != null)
                    {
                        node.Geometry.FirstMaterial = grassArea;
                    }
                    else
                    {
                        grassArea = node.Geometry.FirstMaterial;
                    }
                }

                // Get the water area
                if (node.Geometry.FirstMaterial.Name == "water")
                {
                    waterArea = node.Geometry.FirstMaterial;
                }

                // Temporary workaround because concave shape created from geometry instead of node fails
                SCNNode child = SCNNode.Create();
                node.AddChildNode(child);
                child.Hidden   = true;
                child.Geometry = node.Geometry;
                node.Geometry  = null;
                node.Hidden    = false;

                if (node.Name == "water")
                {
                    node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Water;
                }
            }

            foreach (SCNNode child in node.ChildNodes)
            {
                if (!child.Hidden)
                {
                    SetupCollisionNodes(child);
                }
            }
        }
예제 #30
0
        public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            ARPlaneAnchor planeAnchor = anchor as ARPlaneAnchor;

            if (planeAnchor == null)
            {
                return;
            }

            SCNNode concreteNode = CreateConcreteNode(planeAnchor);

            node.AddChildNode(concreteNode);
        }
예제 #31
0
        public static SCNNode CreateAxesNode(float quiverLength, float quiverThickness)
        {
            quiverThickness = (quiverLength / 50f) * quiverThickness;
            var chamferRadius = quiverThickness / 2f;

            var xQuiverBox = SCNBox.Create(quiverLength, quiverThickness, quiverThickness, chamferRadius);

            xQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Red, false), 0);
            var xQuiverNode = SCNNode.FromGeometry(xQuiverBox);

            xQuiverNode.Position = new SCNVector3((quiverLength / 2f), 0, 0);

            var yQuiverBox = SCNBox.Create(quiverThickness, quiverLength, quiverThickness, chamferRadius);

            yQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Green, false), 0);
            var yQuiverNode = SCNNode.FromGeometry(yQuiverBox);

            yQuiverNode.Position = new SCNVector3(0, (quiverLength / 2f), 0);

            var zQuiverBox = SCNBox.Create(quiverThickness, quiverThickness, quiverLength, chamferRadius);

            zQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Blue, false), 0);
            var zQuiverNode = SCNNode.FromGeometry(zQuiverBox);

            zQuiverNode.Position = new SCNVector3(0, 0, (quiverLength / 2f));

            // Assemble node
            var quiverNode = new SCNNode()
            {
                Name = "Axes"
            };

            quiverNode.AddChildNode(xQuiverNode);
            quiverNode.AddChildNode(yQuiverNode);
            quiverNode.AddChildNode(zQuiverNode);

            // Return results
            return(quiverNode);
        }
예제 #32
0
        public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            if (anchor is ARImageAnchor imageAnchor)
            {
                ARReferenceImage image  = imageAnchor.ReferenceImage;
                nfloat           width  = image.PhysicalSize.Width;
                nfloat           height = image.PhysicalSize.Height;

                PlaneNode planeNode = new PlaneNode(width, height, new SCNVector3(0, 0, 0), UIColor.Red);
                float     angle     = (float)(-Math.PI / 2);
                planeNode.EulerAngles = new SCNVector3(angle, 0, 0);
                node.AddChildNode(planeNode);
            }
        }
예제 #33
0
		public static SCNNode SCAddChildNode (SCNNode container, string name, string path, nfloat scale)
		{
			// Load the scene from the specified file
			var scene = SCNScene.FromFile (path);

			// Retrieve the root node
			var node = scene.RootNode;

			// Search for the node named "name"
			if (name.Length > 0)
				node = node.FindChildNode (name, true);
			else
				node = node.ChildNodes [0]; // Take the first child if no name is passed

			if (scale != 0) {
				// Rescale based on the current bounding box and the desired scale
				// Align the node to 0 on the Y axis
				var min = new SCNVector3 ();
				var max = new SCNVector3 ();
				node.GetBoundingBox (ref min, ref max);

				var mid = SCNVector3.Add (min, max);
				mid = SCNVector3.Multiply (mid, 0.5f);
				mid.Y = min.Y; // Align on bottom

				var size = SCNVector3.Subtract (max, min);
				var maxSize = NMath.Max (NMath.Max (size.X, size.Y), size.Z);

				scale = scale / maxSize;
				mid = SCNVector3.Multiply (mid, scale);
				mid = -mid;

				node.Scale = new SCNVector3 (scale, scale, scale);
				node.Position = new SCNVector3 (mid);
			}

			// Add to the container passed in argument
			container.AddChildNode (node);

			return node;
		}
예제 #34
0
		SCNNode CreateTorchNode ()
		{
			SCNGeometry geometry = SCNBox.Create (20f, 100f, 20f, 0f);
			geometry.FirstMaterial.Diffuse.Contents = AppKit.NSColor.Brown;
			var template = new SCNNode {
				Geometry = geometry
			};

			var particleEmitter = new SCNNode {
				Position = new SCNVector3 (0f, 50f, 0f)
			};

			SCNParticleSystem fire = GameSimulation.LoadParticleSystemWithName ("torch", "spark");
			particleEmitter.AddParticleSystem (fire);
			particleEmitter.Light = TorchLight;

			template.AddChildNode (particleEmitter);
			return template;
		}
예제 #35
0
		public SCNNode CreateLevel ()
		{
			RootNode = new SCNNode ();

			// load level dae and add all root children to the scene.
			var options = new SCNSceneLoadingOptions { ConvertToYUp = true };
			SCNScene scene = SCNScene.FromFile ("level", GameSimulation.PathForArtResource ("level/"), options);
			foreach (SCNNode node in scene.RootNode.ChildNodes)
				RootNode.AddChildNode (node);

			// retrieve the main camera
			Camera = RootNode.FindChildNode ("camera_game", true);

			// create our path that the player character will follow.
			CalculatePathPositions ();

			// Sun/Moon light
			SunLight = RootNode.FindChildNode ("FDirect001", true);
			SunLight.EulerAngles = new SCNVector3 (7.1f * (nfloat)Math.PI / 4, (nfloat)Math.PI / 4, 0f);
			SunLight.Light.ShadowSampleCount = 1;
			lightOffsetFromCharacter = new SCNVector3 (1500f, 2000f, 1000f);

			//workaround directional light deserialization issue
			SunLight.Light.ZNear = 100f;
			SunLight.Light.ZFar = 5000f;
			SunLight.Light.OrthographicScale = 1000f;

			// Torches
			var torchesPos = new float[] { 0f, -1f, 0.092467f, -1f, -1f, 0.5f, 0.792f, 0.95383f };
			for (int i = 0; i < torchesPos.Length; i++) {
				if (torchesPos [i] != -1) {
					SCNVector3 location = LocationAlongPath (torchesPos [i]);
					location.Y += 50;
					location.Z += 150;

					SCNNode node = CreateTorchNode ();

					node.Position = location;
					RootNode.AddChildNode (node);
				}
			}

			// After load, we add nodes that are dynamic / animated / or otherwise not static.
			CreateLavaAnimation ();
			CreateSwingingTorch ();
			AnimateDynamicNodes ();

			// Create our player character
			SCNNode characterRoot = GameSimulation.LoadNodeWithName (string.Empty, "art.scnassets/characters/explorer/explorer_skinned.dae");
			PlayerCharacter = new PlayerCharacter (characterRoot); 
			TimeAlongPath = 0;

			PlayerCharacter.Position = LocationAlongPath (TimeAlongPath);
			PlayerCharacter.Rotation = GetPlayerDirectionFromCurrentPosition ();
			RootNode.AddChildNode (PlayerCharacter);

			// Optimize lighting and shadows
			// only the charadcter should cast shadows
			foreach (var child in RootNode.ChildNodes)
				child.CastsShadow = false;

			foreach (var child in PlayerCharacter.ChildNodes)
				child.CastsShadow = true;

			// Add some monkeys to the scene.
			AddMonkeyAtPosition (new SCNVector3 (0f, -30f, -400f), 0f);
			AddMonkeyAtPosition (new SCNVector3 (3211f, 146f, -400f), -(nfloat)Math.PI / 4f);
			AddMonkeyAtPosition (new SCNVector3 (5200f, 330f, 600f), 0f);

			// Volcano
			SCNNode oldVolcano = RootNode.FindChildNode ("volcano", true);
			string volcanoDaeName = GameSimulation.PathForArtResource ("level/volcano_effects.dae");
			SCNNode newVolcano = GameSimulation.LoadNodeWithName ("dummy_master", volcanoDaeName);

			oldVolcano.AddChildNode (newVolcano);
			oldVolcano.Geometry = null;
			oldVolcano = newVolcano.FindChildNode ("volcano", true);
			oldVolcano = oldVolcano.ChildNodes [0];

			// Animate our dynamic volcano node.
			string shaderCode = "uniform float speed;\n" +
			                    "_geometry.color = vec4(a_color.r, a_color.r, a_color.r, a_color.r);\n" +
			                    "_geometry.texcoords[0] += (vec2(0.0, 1.0) * 0.05 * u_time);\n";

			string fragmentShaderCode = "#pragma transparent\n";

			// Dim background
			SCNNode back = RootNode.FindChildNode ("dumy_rear", true);
			foreach (var child in back.ChildNodes) {
				child.CastsShadow = false;

				if (child.Geometry == null)
					continue;

				foreach (SCNMaterial material in child.Geometry.Materials) {
					material.LightingModelName = SCNLightingModel.Constant;
					material.Multiply.Contents = AppKit.NSColor.FromDeviceWhite (0.3f, 1f);

					material.Multiply.Intensity = 1;
				}
			}

			SCNNode backMiddle = RootNode.FindChildNode ("dummy_middle", true);
			foreach (var child in backMiddle.ChildNodes) {

				if (child.Geometry == null)
					continue;

				foreach (SCNMaterial material in child.Geometry.Materials)
					material.LightingModelName = SCNLightingModel.Constant;
			}

			foreach (var child in newVolcano.ChildNodes)
				foreach (var volc in child.ChildNodes) {
					if (volc != oldVolcano && volc.Geometry != null) {
						volc.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
						volc.Geometry.FirstMaterial.Multiply.Contents = AppKit.NSColor.White;

						volc.Geometry.ShaderModifiers = new SCNShaderModifiers { 
							EntryPointGeometry = shaderCode,
							EntryPointFragment = fragmentShaderCode
						};
					}
				}

			Coconuts = new List<Coconut> ();
			return RootNode;
		}
		void SetupCamera ()
		{
			SCNNode pov = GameView.PointOfView;
			const float altitude = 1f;
			const float distance = 10f;

			cameraYHandle = SCNNode.Create ();
			cameraXHandle = SCNNode.Create ();

			cameraYHandle.Position = new SCNVector3 (0f, altitude, 0f);
			cameraYHandle.AddChildNode (cameraXHandle);
			GameView.Scene.RootNode.AddChildNode (cameraYHandle);

			pov.EulerAngles = new SCNVector3 (0f, 0f, 0f);
			pov.Position = new SCNVector3 (0f, 0f, distance);

			cameraYHandle.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI / 2f + (float)Math.PI / 4f * 3f);
			cameraXHandle.Rotation = new SCNVector4 (1f, 0f, 0f, -(float)Math.PI / 4f * 0.125f);
			cameraXHandle.AddChildNode (pov);

			// Animate camera on launch and prevent the user from manipulating the camera until the end of the animation
			lockCamera = true;
			SCNTransaction.Begin ();
			SCNTransaction.SetCompletionBlock (() => {
				lockCamera = false;
			});

			var cameraYAnimation = CABasicAnimation.FromKeyPath ("rotation.w");
			cameraYAnimation.From = NSNumber.FromDouble (Math.PI * 2 - cameraYHandle.Rotation.W);
			cameraYAnimation.To = NSNumber.FromDouble (0.0);
			cameraYAnimation.Additive = true;
			cameraYAnimation.BeginTime = CAAnimation.CurrentMediaTime () + 3;
			cameraYAnimation.FillMode = CAFillMode.Both;
			cameraYAnimation.Duration = 5.0;
			cameraYAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
			cameraYHandle.AddAnimation (cameraYAnimation, null);

			var cameraXAnimation = CABasicAnimation.FromKeyPath ("rotation.w");
			cameraXAnimation.From = NSNumber.FromDouble (-Math.PI / 2 + cameraXHandle.Rotation.W);	
			cameraXAnimation.To = NSNumber.FromDouble (0.0);
			cameraXAnimation.Additive = true;
			cameraXAnimation.FillMode = CAFillMode.Both;
			cameraXAnimation.Duration = 5.0;
			cameraXAnimation.BeginTime = CAAnimation.CurrentMediaTime () + 3;
			cameraXAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
			cameraXHandle.AddAnimation (cameraXAnimation, null);

			SCNTransaction.Commit ();

			var lookAtConstraint = SCNLookAtConstraint.Create (Character.Node.FindChildNode ("Bip001_Head", true));
			lookAtConstraint.InfluenceFactor = 0;
			pov.Constraints = new SCNConstraint[] { lookAtConstraint };
		}
		void SetupCollisionNodes (SCNNode node)
		{
			if (node.Geometry != null) {
				Console.WriteLine (node.Name);
				node.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
				node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Collision;

				var options = new SCNPhysicsShapeOptions {
					ShapeType = SCNPhysicsShapeType.ConcavePolyhedron
				};
				node.PhysicsBody.PhysicsShape = SCNPhysicsShape.Create (node, options);

				// Get grass area to play the right sound steps
				if (node.Geometry.FirstMaterial.Name == "grass-area") {
					if (grassArea != null)
						node.Geometry.FirstMaterial = grassArea;
					else
						grassArea = node.Geometry.FirstMaterial;
				}

				// Get the water area
				if (node.Geometry.FirstMaterial.Name == "water")
					waterArea = node.Geometry.FirstMaterial;

				// Temporary workaround because concave shape created from geometry instead of node fails
				SCNNode child = SCNNode.Create ();
				node.AddChildNode (child);
				child.Hidden = true;
				child.Geometry = node.Geometry;
				node.Geometry = null;
				node.Hidden = false;

				if (node.Name == "water")
					node.PhysicsBody.CategoryBitMask = (nuint)(int)Bitmask.Water;
			}

			foreach (SCNNode child in node.ChildNodes) {
				if (!child.Hidden)
					SetupCollisionNodes (child);
			}
		}
예제 #38
0
		void SetupEnvironment ()
		{
			// |_   cameraHandle
			//   |_   cameraOrientation
			//     |_   cameraNode

			//create a main camera
			CameraNode = SCNNode.Create ();
			CameraNode.Position = new SCNVector3 (0, 0, 120);

			//create a node to manipulate the camera orientation
			CameraHandle = SCNNode.Create ();
			CameraHandle.Position = new SCNVector3 (0, 60, 0);

			CameraOrientation = SCNNode.Create ();

			Scene.RootNode.AddChildNode (CameraHandle);
			CameraHandle.AddChildNode (CameraOrientation);
			CameraOrientation.AddChildNode (CameraNode);

			CameraNode.Camera = SCNCamera.Create ();
			CameraNode.Camera.ZFar = 800;

			#if __IOS__
			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {
				CameraNode.Camera.YFov = 55;
			} else
			#endif 
			{
				CameraNode.Camera.XFov = 75;
			}

			for (int i = 0; i < SLIDE_COUNT; i++) {
				CameraHandleTransforms.Add (new SCNMatrix4 ());
				CameraOrientationTransforms.Add (new SCNMatrix4 ());
			}
			CameraHandleTransforms [0] = CameraNode.Transform;

			// add an ambient light
			AmbientLightNode = SCNNode.Create ();
			AmbientLightNode.Light = SCNLight.Create ();

			AmbientLightNode.Light.LightType = SCNLightType.Ambient;
			AmbientLightNode.Light.Color = SKColorHelper.FromCommonWhiteAlpha (0.3f, 1.0f);

			Scene.RootNode.AddChildNode (AmbientLightNode);


			//add a key light to the scene
			SpotLightParentNode = SCNNode.Create ();
			SpotLightParentNode.Position = new SCNVector3 (0, 90, 20);

			SpotLightNode = SCNNode.Create ();
			SpotLightNode.Rotation = new SCNVector4 (1, 0, 0, -(float)Math.PI / 4);

			SpotLightNode.Light = SCNLight.Create ();
			SpotLightNode.Light.LightType = SCNLightType.Spot;
			SpotLightNode.Light.Color = SKColorHelper.FromCommonWhiteAlpha (1.0f, 1.0f);
			SpotLightNode.Light.CastsShadow = true;
			SpotLightNode.Light.ShadowColor = SKColorHelper.FromCommonWhiteAlpha (0, 0.5f);
			SpotLightNode.Light.ZNear = 30;
			SpotLightNode.Light.ZFar = 800;
			SpotLightNode.Light.ShadowRadius = 1.0f;
			SpotLightNode.Light.SpotInnerAngle = 15;
			SpotLightNode.Light.SpotOuterAngle = 70;

			CameraNode.AddChildNode (SpotLightParentNode);
			SpotLightParentNode.AddChildNode (SpotLightNode);


			//floor
			var floor = SCNFloor.Create ();
			floor.ReflectionFalloffEnd = 0;
			floor.Reflectivity = 0;

			FloorNode = SCNNode.Create ();
			FloorNode.Geometry = floor;
			#if __IOS__
			FloorNode.Geometry.FirstMaterial.Diffuse.Contents = new UIImage ("images/wood.png");
			#else
			FloorNode.Geometry.FirstMaterial.Diffuse.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/wood", "png"));
			#endif
			FloorNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			FloorNode.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Repeat;
			FloorNode.Geometry.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Repeat;
			FloorNode.Geometry.FirstMaterial.Diffuse.MipFilter = SCNFilterMode.Linear;

			FloorNode.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			FloorNode.PhysicsBody.Restitution = 1.0f;

			Scene.RootNode.AddChildNode (FloorNode);
		}
예제 #39
0
		private void SetupLookAtScene ()
		{
			var intermediateNode = SCNNode.Create ();
			intermediateNode.Scale = new SCNVector3 (0.5f, 0.5f, 0.5f);
			intermediateNode.Position = new SCNVector3 (0, 0, 10);
			ContentNode.AddChildNode (intermediateNode);

			var ballMaterial = SCNMaterial.Create ();
			ballMaterial.Diffuse.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("Scenes/pool/pool_8", "png"));
			ballMaterial.Specular.Contents = NSColor.White;
			ballMaterial.Shininess = 0.9f; // shinny
			ballMaterial.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("SharedTextures/color_envmap", "png"));
			ballMaterial.Reflective.Intensity = 0.5f;

			// Node hierarchy for the ball :
			//   _ballNode
			//  |__ cameraTarget      : the target for the "look at" constraint
			//  |__ ballRotationNode  : will rotate to animate the rolling ball
			//      |__ ballPivotNode : will own the geometry and will be rotated so that the "8" faces the camera at the beginning

			BallNode = SCNNode.Create ();
			BallNode.Rotation = new SCNVector4 (0, 1, 0, (float)(Math.PI / 4));
			intermediateNode.AddChildNode (BallNode);

			var cameraTarget = SCNNode.Create ();
			cameraTarget.Name = "cameraTarget";
			cameraTarget.Position = new SCNVector3 (0, 6, 0);
			BallNode.AddChildNode (cameraTarget);

			var ballRotationNode = SCNNode.Create ();
			ballRotationNode.Position = new SCNVector3 (0, 4, 0);
			BallNode.AddChildNode (ballRotationNode);

			var ballPivotNode = SCNNode.Create ();
			ballPivotNode.Geometry = SCNSphere.Create (4.0f);
			ballPivotNode.Geometry.FirstMaterial = ballMaterial;
			ballPivotNode.Rotation = new SCNVector4 (0, 1, 0, (float)(Math.PI / 2));
			ballRotationNode.AddChildNode (ballPivotNode);

			var arrowMaterial = SCNMaterial.Create ();
			arrowMaterial.Diffuse.Contents = NSColor.White;
			arrowMaterial.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("SharedTextures/chrome", "jpg"));

			var arrowContainer = SCNNode.Create ();
			arrowContainer.Name = "arrowContainer";
			intermediateNode.AddChildNode (arrowContainer);

			var arrowPath = Utils.SCArrowBezierPath (new CGSize (6, 2), new CGSize (3, 5), 0.5f, false);
			// Create the arrows
			for (var i = 0; i < 11; i++) {
				var arrowNode = SCNNode.Create ();
				arrowNode.Position = new SCNVector3 (NMath.Cos (NMath.PI * i / 10.0f) * 20.0f, 3 + 18.5f * NMath.Sin (NMath.PI * i / 10.0f), 0);

				var arrowGeometry = SCNShape.Create (arrowPath, 1);
				arrowGeometry.ChamferRadius = 0.2f;

				var arrowSubNode = SCNNode.Create ();
				arrowSubNode.Geometry = arrowGeometry;
				arrowSubNode.Geometry.FirstMaterial = arrowMaterial;
				arrowSubNode.Pivot = SCNMatrix4.CreateTranslation (new SCNVector3 (0, 2.5f, 0)); // place the pivot (center of rotation) at the middle of the arrow
				arrowSubNode.Rotation = new SCNVector4 (0, 0, 1, (float)(Math.PI / 2));

				arrowNode.AddChildNode (arrowSubNode);
				arrowContainer.AddChildNode (arrowNode);
			}
		}
예제 #40
0
		void SetupIntroEnvironment ()
		{
			IntroductionStep = 1;

			// configure the lighting for the introduction (dark lighting)
			AmbientLightNode.Light.Color = SKColor.Black;
			SpotLightNode.Light.Color = SKColor.Black;
			SpotLightNode.Position = new SCNVector3 (50, 90, -50);
			SpotLightNode.EulerAngles = new SCNVector3 (-(float)(Math.PI / 2) * 0.75f, (float)(Math.PI / 4) * 0.5f, 0);

			//put all texts under this node to remove all at once later
			IntroNodeGroup = SCNNode.Create ();

			//Slide 1
			var sceneKitLogo = SCNNode.FromGeometry (SCNPlane.Create (LOGO_SIZE, LOGO_SIZE));
			#if __IOS__
			sceneKitLogo.Geometry.FirstMaterial.Diffuse.Contents = new UIImage ("images/SceneKit.png");
			sceneKitLogo.Geometry.FirstMaterial.Emission.Contents = new UIImage ("images/SceneKit.png");
			#else
			sceneKitLogo.Geometry.FirstMaterial.Diffuse.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/SceneKit", "png"));
			sceneKitLogo.Geometry.FirstMaterial.Emission.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/SceneKit", "png"));
			#endif
			sceneKitLogo.Geometry.FirstMaterial.Emission.Intensity = 0;

			IntroNodeGroup.AddChildNode (sceneKitLogo);
			sceneKitLogo.Position = new SCNVector3 (200, LOGO_SIZE / 2, 1050);

			var position = new SCNVector3 (200, 0, 1000);

			CameraNode.Position = new SCNVector3 (200, -20, position.Z + 150);
			CameraNode.EulerAngles = new SCNVector3 (-(float)(Math.PI / 2) * 0.06f, 0, 0);


			//slide 2
			var text = SCNText.Create ("Load\n3D Scenes", 5);
			text.ChamferRadius = 0.3f;
			text.Flatness = 0.1f;
			#if __IOS__
			text.Font = UIFont.FromName ("Avenir Heavy", 30);
			#else
			text.Font = NSFont.FromFontName ("Avenir Heavy", 30);
			#endif
			text.Materials = new SCNMaterial[] { TextMaterial () };
			var textNode = SCNNode.Create ();
			textNode.Geometry = text;
			textNode.Scale = new SCNVector3 (TEXT_SCALE, TEXT_SCALE, TEXT_SCALE);

			position.Z -= TEXT_Z_SPACING;
			var min = new SCNVector3 ();
			var max = new SCNVector3 ();
			textNode.GetBoundingBox (ref min, ref max);

			position = new SCNVector3 (110, -min.Y * TEXT_SCALE, position.Z);
			textNode.Position = position;
			IntroNodeGroup.AddChildNode (textNode);

			/* hierarchy
		     shipHandle
		     |_ shipXTranslate
		     |_ shipPivot
		     |_ ship */
			var modelScene = SCNScene.FromFile ("assets.scnassets/models/ship");
			ShipNode = modelScene.RootNode.FindChildNode ("Aircraft", true);
			ShipNode.Opacity = 0;

			ShipPivot = SCNNode.Create ();
			var shipXTranslate = SCNNode.Create ();
			ShipHandle = SCNNode.Create ();

			ShipHandle.Position = new SCNVector3 (200, 0, position.Z + 30);
			ShipNode.Position = new SCNVector3 (50, 30, 0);

			ShipPivot.AddChildNode (ShipNode);
			shipXTranslate.AddChildNode (ShipPivot);
			ShipHandle.AddChildNode (shipXTranslate);
			IntroNodeGroup.AddChildNode (ShipHandle);


			//slide 3
			text = SCNText.Create ("Animate & Render", 5);
			text.ChamferRadius = 0.3f;
			text.Flatness = 0.1f;
			#if __IOS__
			text.Font = UIFont.FromName ("Avenir Heavy", 30);
			#else
			text.Font = NSFont.FromFontName ("Avenir Heavy", 30);
			#endif
			text.Materials = new [] { TextMaterial () };
			textNode = SCNNode.Create ();
			textNode.Geometry = text;
			textNode.Scale = new SCNVector3 (TEXT_SCALE, TEXT_SCALE, TEXT_SCALE);

			position.Z -= TEXT_Z_SPACING;
			textNode.GetBoundingBox (ref min, ref max);

			position = new SCNVector3 (100, -min.Y * TEXT_SCALE, position.Z);
			textNode.Position = position;
			IntroNodeGroup.AddChildNode (textNode);


			//slide 4
			text = SCNText.Create ("OS X    iOS", 5);
			text.ChamferRadius = 0.3f;
			text.Flatness = 0.1f;
			#if __IOS__
			text.Font = UIFont.FromName ("Avenir Heavy", 50);
			#else
			text.Font = NSFont.FromFontName ("Avenir Heavy", 50);
			#endif
			text.Materials = new [] { TextMaterial () };
			textNode = SCNNode.Create ();
			textNode.Geometry = text;
			textNode.Scale = new SCNVector3 (TEXT_SCALE, TEXT_SCALE, TEXT_SCALE);

			position.Z -= TEXT_Z_SPACING;
			position.Z -= TEXT_Z_SPACING;
			textNode.GetBoundingBox (ref min, ref max);

			position = new SCNVector3 (200 - (max.X - min.X) * TEXT_SCALE * 0.5f, -min.Y * TEXT_SCALE, position.Z);
			textNode.Position = position;
			IntroNodeGroup.AddChildNode (textNode);

			Scene.RootNode.AddChildNode (IntroNodeGroup);

			//wait, then fade in light
			SCNTransaction.Begin ();
			SCNTransaction.AnimationDuration = 1;
			SCNTransaction.SetCompletionBlock (() => {
				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 2.5f;

				SpotLightNode.Light.Color = SKColorHelper.FromCommonWhiteAlpha (1, 1);
				sceneKitLogo.Geometry.FirstMaterial.Emission.Intensity = 0.75f;

				SCNTransaction.Commit ();
			});

			SpotLightNode.Light.Color = SKColorHelper.FromCommonWhiteAlpha (0.001f, 1);

			SCNTransaction.Commit ();
		}
예제 #41
0
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Set the slide's title and subtile and add some text
			TextManager.SetTitle ("Node Attributes");
			TextManager.SetSubtitle ("SCNGeometry");

			TextManager.AddBulletAtLevel ("Triangles", 0);
			TextManager.AddBulletAtLevel ("Vertices", 0);
			TextManager.AddBulletAtLevel ("Normals", 0);
			TextManager.AddBulletAtLevel ("UVs", 0);
			TextManager.AddBulletAtLevel ("Materials", 0);

			// We create a container for several versions of the teapot model
			// - one teapot to show positions and normals
			// - one teapot to show texture coordinates
			// - one teapot to show materials
			var allTeapotsNode = SCNNode.Create ();
			allTeapotsNode.Rotation = new SCNVector4 (1, 0, 0, -(float)(Math.PI / 2));
			GroundNode.AddChildNode (allTeapotsNode);

			TeapotNodeForPositionsAndNormals = Utils.SCAddChildNode (allTeapotsNode, "TeapotLowRes", "Scenes.scnassets/teapots/teapotLowRes", 17);
			TeapotNodeForUVs = Utils.SCAddChildNode (allTeapotsNode, "Teapot", "Scenes.scnassets/teapots/teapot", 17);
			TeapotNodeForMaterials = Utils.SCAddChildNode (allTeapotsNode, "teapotMaterials", "Scenes.scnassets/teapots/teapotMaterial", 17);

			TeapotNodeForPositionsAndNormals.Position = new SCNVector3 (4, 0, 0);
			TeapotNodeForUVs.Position = new SCNVector3 (4, 0, 0);
			TeapotNodeForMaterials.Position = new SCNVector3 (4, 0, 0);

			foreach (var child in TeapotNodeForMaterials.ChildNodes) {
				foreach (var material in child.Geometry.Materials) {
					material.Multiply.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("Scenes.scnassets/teapots/UVs", "png"));
					material.Multiply.WrapS = SCNWrapMode.Repeat;
					material.Multiply.WrapT = SCNWrapMode.Repeat;
					//material.Reflective.Contents = NSColor.White;
					//material.Reflective.Intensity = 3.0f;
					//material.FresnelExponent = 3.0f;
				}
			}

			// Animate the teapots (rotate forever)
			var rotationAnimation = CABasicAnimation.FromKeyPath ("rotation");
			rotationAnimation.Duration = 40.0f;
			rotationAnimation.RepeatCount = float.MaxValue;
			rotationAnimation.To = NSValue.FromVector (new SCNVector4 (0, 0, 1, (float)(Math.PI * 2)));

			TeapotNodeForPositionsAndNormals.AddAnimation (rotationAnimation, new NSString ("teapotNodeForPositionsAndNormalsAnimation"));
			TeapotNodeForUVs.AddAnimation (rotationAnimation, new NSString ("teapotNodeForUVsAnimation"));
			TeapotNodeForMaterials.AddAnimation (rotationAnimation, new NSString ("teapotNodeForMaterialsAnimation"));

			// Load the "explode" shader modifier and add it to the geometry
			//var explodeShaderPath = NSBundle.MainBundle.PathForResource ("Shaders/explode", "shader");
			//var explodeShaderSource = System.IO.File.ReadAllText (explodeShaderPath);
			// TODO TeapotNodeForPositionsAndNormals.Geometry.ShaderModifiers = new SCNShaderModifiers { EntryPointGeometry = explodeShaderSource };

			PositionsVisualizationNode = SCNNode.Create ();
			NormalsVisualizationNode = SCNNode.Create ();

			// Build nodes that will help visualize the vertices (position and normal)
			BuildVisualizationsOfNode (TeapotNodeForPositionsAndNormals, ref PositionsVisualizationNode, ref NormalsVisualizationNode);

			NormalsVisualizationNode.CastsShadow = false;

			TeapotNodeForMaterials.AddChildNode (PositionsVisualizationNode);
			TeapotNodeForMaterials.AddChildNode (NormalsVisualizationNode);
		}
예제 #42
0
		public static SCNNode SharedScenegraphDiagramNode ()
		{
			if (DiagramNode == null) {
				DiagramNode = SCNNode.Create ();
				DiagramNode.Opacity = 0.0f;


				// "Scene"
				var blue = NSColor.FromDeviceRgba (49.0f / 255.0f, 80.0f / 255.0f, 201.0f / 255.0f, 1);
				var box = Utils.SCBoxNode ("Scene", new CGRect (-53.5f, -25, 107, 50), blue, 10, true);
				box.Name = "scene";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.4f, 4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrow from "Scene" to "Root Node"
				var arrowNode = new SCNNode {
					Name = "sceneArrow",
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (3, 0.2f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Scale = new SCNVector3 (20, 20, 1),
					Position = new SCNVector3 (-5, 0, 8),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = blue;
				box.AddChildNode (arrowNode);


				// "Root Node"
				var green = NSColor.FromDeviceRgba (154.0f / 255.0f, 197.0f / 255.0f, 58.0f / 255.0f, 1);
				box = Utils.SCBoxNode ("Root Node", new CGRect (-40, -36, 80, 72), green, 10, true);
				box.Name = "rootNode";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.405f, 1.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrows from "Root Node" to child nodes
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow1";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (5.8f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, true), 0);
				arrowNode.Position = new SCNVector3 (0, -30, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * 0.85f));
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow2";
				arrowNode.Position = new SCNVector3 (0, -43, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * (1 - 0.85f)));
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "nodeArrow3";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.6f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, true), 0);
				arrowNode.Position = new SCNVector3 (-4, -38, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI * 0.5f));
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
				box.AddChildNode (arrowNode);


				// Multiple "Child Node"
				box = Utils.SCBoxNode ("Child Node", new CGRect (-40, -36, 80, 72), green, 10, true);
				box.Name = "child1";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (2.405f, -2, 0);
				DiagramNode.AddChildNode (box);

				box = box.Clone ();
				box.Name = "child2";
				box.Position = new SCNVector3 (5.405f, -2, 0);
				DiagramNode.AddChildNode (box);

				box = box.Clone ();
				box.Name = "child3";
				box.Position = new SCNVector3 (8.405f, -2, 0);
				DiagramNode.AddChildNode (box);


				// "Light"
				var purple = NSColor.FromDeviceRgba (190.0f / 255.0f, 56.0f / 255.0f, 243.0f / 255.0f, 1);
				box = Utils.SCBoxNode ("Light", new CGRect (-40, -20, 80, 40), purple, 10, true);
				box.Name = "light";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (2.405f, -4.8f, 0);
				DiagramNode.AddChildNode (box);
				

				// Arrow to "Light"
				arrowNode = new SCNNode {
					Name = "lightArrow",
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Position = new SCNVector3 (-5, 60, 8),
					Scale = new SCNVector3 (20, 20, 1),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
				box.AddChildNode (arrowNode);


				// "Camera"
				box = Utils.SCBoxNode ("Camera", new CGRect (-45, -20, 90, 40), purple, 10, true);
				box.Name = "camera";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (5.25f, -4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrow to "Camera"
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "cameraArrow";
				arrowNode.Position = new SCNVector3 (0, 60, 8);
				box.AddChildNode (arrowNode);


				// "Geometry"
				box = Utils.SCBoxNode ("Geometry", new CGRect (-55, -20, 110, 40), purple, 10, true);
				box.Name = "geometry";
				box.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				box.Position = new SCNVector3 (8.6f, -4.8f, 0);
				DiagramNode.AddChildNode (box);


				// Arrows to "Geometry"
				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "geometryArrow";
				arrowNode.Position = new SCNVector3 (-10, 60, 8);
				box.AddChildNode (arrowNode);

				arrowNode = arrowNode.Clone ();
				arrowNode.Name = "geometryArrow2";
				arrowNode.Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (5.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0);
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
				arrowNode.Position = new SCNVector3 (-105, 53, 8);
				arrowNode.Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 8));
				box.AddChildNode (arrowNode);


				// Multiple "Material"
				var redColor = NSColor.FromDeviceRgba (168.0f / 255.0f, 21.0f / 255.0f, 0.0f / 255.0f, 1);

				var materialsBox = Utils.SCBoxNode (null, new CGRect (-151, -25, 302, 50), NSColor.LightGray, 2, true);
				materialsBox.Scale = new SCNVector3 (0.03f, 0.03f, 0.03f);
				materialsBox.Name = "materials";
				materialsBox.Position = new SCNVector3 (8.7f, -7.1f, -0.2f);
				DiagramNode.AddChildNode (materialsBox);

				box = Utils.SCBoxNode ("Material", new CGRect (-45, -20, 90, 40), redColor, 0, true);
				box.Position = new SCNVector3 (-100, 0, 0.2f);
				materialsBox.AddChildNode (box);

				box = box.Clone ();
				box.Position = new SCNVector3 (100, 0, 0.2f);
				materialsBox.AddChildNode (box);

				box = box.Clone ();
				box.Position = new SCNVector3 (0, 0, 0.2f);
				materialsBox.AddChildNode (box);

				// Arrow from "Geometry" to the materials
				arrowNode = new SCNNode {
					Geometry = SCNShape.Create (Utils.SCArrowBezierPath (new CGSize (2.0f, 0.15f), new CGSize (0.5f, 0.7f), 0.2f, false), 0),
					Position = new SCNVector3 (-6, 65, 8),
					Scale = new SCNVector3 (20, 20, 1),
					Rotation = new SCNVector4 (0, 0, 1, -(float)(Math.PI / 2))
				};
				arrowNode.Geometry.FirstMaterial.Diffuse.Contents = redColor;
				box.AddChildNode (arrowNode);

				materialsBox.ParentNode.ReplaceChildNode (materialsBox, materialsBox.FlattenedClone ());
			}
			return DiagramNode;
		}
예제 #43
0
		void ShowShadersSlide ()
		{
			ShaderStage = 0;

			//move the camera back
			//place camera
			SCNTransaction.Begin ();
			SCNTransaction.AnimationDuration = 1;
			CameraHandle.Position = new SCNVector3 (CameraHandle.Position.X + 180, 60, 0);
			CameraHandle.EulerAngles = new SCNVector3 (-(float)(Math.PI / 4) * 0.3f, 0, 0);

			SpotLightNode.Light.SpotOuterAngle = 55;
			SCNTransaction.Commit ();

			ShaderGroupNode = SCNNode.Create ();
			ShaderGroupNode.Position = new SCNVector3 (CameraHandle.Position.X, -5, 20);
			Scene.RootNode.AddChildNode (ShaderGroupNode);

			//add globe stand
			var globe = SCNScene.FromFile ("assets.scnassets/models/globe").RootNode.FindChildNode ("globe", true);

			ShaderGroupNode.AddChildNode (globe);

			//show shader modifiers
			//add spheres
			var sphere = SCNSphere.Create (28);
			sphere.SegmentCount = 48;
			sphere.FirstMaterial.Shininess = 0.1f;
			sphere.FirstMaterial.FresnelExponent = 2;

			#if __IOS__
			sphere.FirstMaterial.Diffuse.Contents = new UIImage ("images/earth/earth-diffuse.jpg");
			sphere.FirstMaterial.Specular.Contents = new UIImage ("images/earth/earth-specular.jpg");
			sphere.FirstMaterial.Reflective.Contents = new UIImage ("images/envmap.jpg");
			#else
			sphere.FirstMaterial.Diffuse.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/earth/earth-diffuse", "jpg"));
			sphere.FirstMaterial.Specular.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/earth/earth-specular", "jpg"));
			sphere.FirstMaterial.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/envmap", "jpg"));
			#endif

			sphere.FirstMaterial.Specular.Intensity = 0.2f;
			sphere.FirstMaterial.Reflective.Intensity = 0.5f;

			//GEOMETRY
			var node = globe.FindChildNode ("globeAttach", true);
			node.Geometry = sphere;
			node.Scale = new SCNVector3 (3, 3, 3);

			node.RunAction (SCNAction.RepeatActionForever (SCNAction.RotateBy (0, NMath.PI, 0, 4.0)));

			var geoModifier = File.ReadAllText (NSBundle.MainBundle.PathForResource ("shaders/sm_geom", "shader"));
			var surfaceModifier = File.ReadAllText (NSBundle.MainBundle.PathForResource ("shaders/sm_surf", "shader"));
			var fragmentModifier = File.ReadAllText (NSBundle.MainBundle.PathForResource ("shaders/sm_frag", "shader"));
			var lightingModifier = File.ReadAllText (NSBundle.MainBundle.PathForResource ("shaders/sm_light", "shader"));

			node.Geometry.ShaderModifiers = new SCNShaderModifiers {
				EntryPointGeometry = geoModifier,
				EntryPointSurface = surfaceModifier,
				EntryPointFragment = fragmentModifier,
				EntryPointLightingModel = lightingModifier,
			};


			node.Geometry.SetValueForKey (new NSNumber (0), new NSString ("Amplitude"));
			node.Geometry.SetValueForKey (new NSNumber (0), new NSString ("lightIntensity"));
			node.Geometry.SetValueForKey (new NSNumber (0), new NSString ("surfIntensity"));
			node.Geometry.SetValueForKey (new NSNumber (0), new NSString ("fragIntensity"));

			ShadedNode = node;

			//redraw forever
			((SCNView)View).Playing = true;
			((SCNView)View).Loops = true;
		}
예제 #44
0
		public override void PresentStep (int index, PresentationViewController presentationViewController)
		{
			switch (index) {
			case 0:
				// Set the slide's title and subtile and add some code
				TextManager.SetTitle ("Performance");
				TextManager.SetSubtitle ("Statistics");

				TextManager.AddCode ("#// Show statistics \n"
				+ "aSCNView.#ShowsStatistics# = true;");
				break;
			case 1:
				// Place a screenshot in the scene and animate it
				WindowNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/statistics/statistics", "png"), 20, true);
				ContentNode.AddChildNode (WindowNode);

				WindowNode.Opacity = 0.0f;
				WindowNode.Position = new SCNVector3 (20, 5.2f, 9);
				WindowNode.Rotation = new SCNVector4 (0, 1, 0, -(float)(Math.PI / 4));

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 1;
				WindowNode.Opacity = 1.0f;
				WindowNode.Position = new SCNVector3 (0, 5.2f, 7);
				WindowNode.Rotation = new SCNVector4 (0, 1, 0, 0);
				SCNTransaction.Commit ();

				// The screenshot contains transparent areas so we need to make sure it is rendered
				// after the text (which also sets its rendering order)
				WindowNode.RenderingOrder = 2;

				break;
			case 2:
				FpsNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/statistics/statistics-fps", "png"), 7, false);
				WindowNode.AddChildNode (FpsNode);

				FpsNode.Scale = new SCNVector3 (0.75f, 0.75f, 0.75f);
				FpsNode.Opacity = 0.0f;
				FpsNode.Position = new SCNVector3 (-6, -3, 0.5f);
				FpsNode.RenderingOrder = 4;

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 0.5f;
				FpsNode.Scale = new SCNVector3 (1.0f, 1.0f, 1.0f);
				FpsNode.Opacity = 1.0f;
				SCNTransaction.Commit ();
				break;
			case 3:
				ButtonNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/statistics/statistics-button", "png"), 4, false);
				WindowNode.AddChildNode (ButtonNode);

				ButtonNode.Scale = new SCNVector3 (0.75f, 0.75f, 0.75f);
				ButtonNode.Opacity = 0.0f;
				ButtonNode.Position = new SCNVector3 (-7.5f, -2.75f, 0.5f);
				ButtonNode.RenderingOrder = 5;

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 0.5f;
				FpsNode.Opacity = 0.0f;
				ButtonNode.Scale = new SCNVector3 (1.0f, 1.0f, 1.0f);
				ButtonNode.Opacity = 1.0f;
				SCNTransaction.Commit ();
				break;
			case 4:
				PanelNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/statistics/control-panel", "png"), 10, false);
				WindowNode.AddChildNode (PanelNode);

				PanelNode.Scale = new SCNVector3 (0.75f, 0.75f, 0.75f);
				PanelNode.Opacity = 0.0f;
				PanelNode.Position = new SCNVector3 (3.5f, -0.5f, 1.5f);
				PanelNode.RenderingOrder = 6;

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 0.5f;
				PanelNode.Scale = new SCNVector3 (1.0f, 1.0f, 1.0f);
				PanelNode.Opacity = 1.0f;
				SCNTransaction.Commit ();
				break;
			case 5:
				var detailsNode = Utils.SCPlaneNode (NSBundle.MainBundle.PathForResource ("Images/statistics/statistics-detail", "png"), 9, false);
				WindowNode.AddChildNode (detailsNode);

				detailsNode.Scale = new SCNVector3 (0.75f, 0.75f, 0.75f);
				detailsNode.Opacity = 0.0f;
				detailsNode.Position = new SCNVector3 (5, -2.75f, 1.5f);
				detailsNode.RenderingOrder = 7;

				SCNTransaction.Begin ();
				SCNTransaction.AnimationDuration = 0.5f;
				PanelNode.Opacity = 0.0f;
				ButtonNode.Opacity = 0.0f;
				detailsNode.Scale = new SCNVector3 (1.0f, 1.0f, 1.0f);
				detailsNode.Opacity = 1.0f;
				SCNTransaction.Commit ();
				break;
			}
		}