Пример #1
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Create the font and the materials that will be shared among the features in the word cloud
            Font = NSFont.FromFontName("Myriad Set BoldItalic", 50) != null?NSFont.FromFontName("Myriad Set BoldItalic", 50) : NSFont.FromFontName("Avenir Heavy Oblique", 50);

            var frontAndBackMaterial = SCNMaterial.Create();
            var sideMaterial         = SCNMaterial.Create();

            sideMaterial.Diffuse.Contents = NSColor.DarkGray;

            Materials = new SCNMaterial[] { frontAndBackMaterial, sideMaterial, frontAndBackMaterial };

            // Add different features to the word cloud
            PlaceFeature("Techniques", new CGPoint(10, -8), 0);
            PlaceFeature("SpriteKit materials", new CGPoint(-16, -7), 0.05f);
            PlaceFeature("Inverse Kinematics", new CGPoint(-12, -6), 0.1f);
            PlaceFeature("Actions", new CGPoint(-10, 6), 0.15f);
            PlaceFeature("SKTexture", new CGPoint(4, 9), 0.2f);
            PlaceFeature("JavaScript", new CGPoint(-4, 8), 0.25f);
            PlaceFeature("Alembic", new CGPoint(-3, -8), 0.3f);
            PlaceFeature("OpenSubdiv", new CGPoint(-1, 6), 0.35f);
            PlaceFeature("Assets catalog", new CGPoint(1, 5), 0.85f);
            PlaceFeature("SIMD bridge", new CGPoint(3, -6), 0.45f);
            PlaceFeature("Physics", new CGPoint(-0.5f, 0), 0.47f);
            PlaceFeature("Vehicle", new CGPoint(5, 3), 0.50f);
            PlaceFeature("Fog", new CGPoint(7, 2), 0.95f);
            PlaceFeature("SpriteKit Overlays", new CGPoint(-10, 1), 0.60f);
            PlaceFeature("Particles", new CGPoint(-13, -1), 0.65f);
            PlaceFeature("Forward shadows", new CGPoint(8, -1), 0.7f);
            PlaceFeature("Snapshot", new CGPoint(6, -2), 0.75f);
            PlaceFeature("Physics Fields", new CGPoint(-6, -3), 0.8f);
            PlaceFeature("Archiving", new CGPoint(-11, 3), 0.9f);
            PlaceFeature("Performance tools", new CGPoint(-2, -5), 1);
        }
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            if (touches.AnyObject is UITouch touch)
            {
                var point = touch.LocationInView(SceneView);

                var hitTestOptions = new SCNHitTestOptions();

                var hits = SceneView.HitTest(point, hitTestOptions);
                var hit  = hits.FirstOrDefault();

                if (hit == null)
                {
                    return;
                }

                var node = hit.Node;

                if (node == null)
                {
                    return;
                }

                var redMaterial = new SCNMaterial();
                redMaterial.Diffuse.Contents = UIColor.Purple;

                node.Geometry.Materials = new SCNMaterial[] { redMaterial };
            }
        }
Пример #3
0
		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;
		}
Пример #4
0
        private SCNMaterial WallMaterial()
        {
            var material = SCNMaterial.Create();

            material.Diffuse.Contents = NSColor.FromDeviceRgba(0.11f, 0.70f, 0.88f, 1.0f);
            return(material);
        }
Пример #5
0
        private SCNNode CreatePlane(ARReferenceImage detectecImage)
        {
            nfloat width  = detectecImage.PhysicalSize.Width;
            nfloat height = detectecImage.PhysicalSize.Height;

            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = UIColor.Blue;
            material.DoubleSided      = false;

            SCNPlane geometry = SCNPlane.Create(width, height);

            geometry.Materials = new[] { material };

            SCNNode planeNode = new SCNNode
            {
                Geometry = geometry,
                Position = new SCNVector3(0, 0, 0)
            };

            float angle = (float)(-Math.PI / 2);

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

            return(planeNode);
        }
		// Queries the root node for the expected nodes.
		internal GameNodes (SCNNode sceneRoot)
		{
			Object = sceneRoot.FindChildNode ("teapot", true);
			if (Object == null)
				throw new InvalidProgramException ();

			ObjectMaterial = Object.Geometry?.FirstMaterial;
			if (ObjectMaterial == null)
				throw new InvalidProgramException ();

			Confetti = sceneRoot.FindChildNode ("particles", true);
			if (Confetti == null)
				throw new InvalidProgramException ();

			Camera = sceneRoot.FindChildNode ("camera", true).Camera;
			if (Camera == null)
				throw new InvalidProgramException ();

			CountdownLabel = new SKLabelNode ("Chalkduster") {
				HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center
			};

			CongratulationsLabel = new SKLabelNode ("Chalkduster") {
				FontColor = GameColors.DefaultFont,
				Text = "You Win!",
				FontSize = 45
			};
		}
Пример #7
0
        private void SelectNode(SCNNode node, nint index)
        {
            // Unhighlight the previous selection.
            this.selectedMaterial?.Emission?.RemoveAllAnimations();
            // Clear the selection.
            this.selectedMaterial = null;

            // Highight the selection, if there is one.
            if (node != null && index != -1)
            {
                // Convert the geometry element index to a material index.
                index = index % node.Geometry.Materials.Count();

                // Make the material unique (i.e. unshared).
                SCNMaterial unsharedMaterial = node.Geometry.Materials[index].Copy() as SCNMaterial;
                node.Geometry.ReplaceMaterial(index, unsharedMaterial);

                // Select the material.
                this.selectedMaterial = unsharedMaterial;

                // Animate the material.
                var highlightAnimation = CABasicAnimation.FromKeyPath("contents") as CABasicAnimation;
                highlightAnimation.To             = NSColor.Blue;
                highlightAnimation.From           = NSColor.Black;
                highlightAnimation.RepeatCount    = float.MaxValue;
                highlightAnimation.AutoReverses   = true;
                highlightAnimation.Duration       = 0.5;
                highlightAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

                this.selectedMaterial.Emission.AddAnimation(highlightAnimation, new NSString("highlight"));
            }
        }
Пример #8
0
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Create the font and the materials that will be shared among the features in the word cloud
			Font = NSFont.FromFontName ("Myriad Set BoldItalic", 50) != null ? NSFont.FromFontName ("Myriad Set BoldItalic", 50) : NSFont.FromFontName ("Avenir Heavy Oblique", 50);

			var frontAndBackMaterial = SCNMaterial.Create ();
			var sideMaterial = SCNMaterial.Create ();
			sideMaterial.Diffuse.Contents = NSColor.DarkGray;

			Materials = new SCNMaterial[] { frontAndBackMaterial, sideMaterial, frontAndBackMaterial };

			// Add different features to the word cloud
			PlaceFeature ("Techniques", new CGPoint (10, -8), 0);
			PlaceFeature ("SpriteKit materials", new CGPoint (-16, -7), 0.05f);
			PlaceFeature ("Inverse Kinematics", new CGPoint (-12, -6), 0.1f);
			PlaceFeature ("Actions", new CGPoint (-10, 6), 0.15f);
			PlaceFeature ("SKTexture", new CGPoint (4, 9), 0.2f);
			PlaceFeature ("JavaScript", new CGPoint (-4, 8), 0.25f);
			PlaceFeature ("Alembic", new CGPoint (-3, -8), 0.3f);
			PlaceFeature ("OpenSubdiv", new CGPoint (-1, 6), 0.35f);
			PlaceFeature ("Assets catalog", new CGPoint (1, 5), 0.85f);
			PlaceFeature ("SIMD bridge", new CGPoint (3, -6), 0.45f);
			PlaceFeature ("Physics", new CGPoint (-0.5f, 0), 0.47f);
			PlaceFeature ("Vehicle", new CGPoint (5, 3), 0.50f);
			PlaceFeature ("Fog", new CGPoint (7, 2), 0.95f);
			PlaceFeature ("SpriteKit Overlays", new CGPoint (-10, 1), 0.60f);
			PlaceFeature ("Particles", new CGPoint (-13, -1), 0.65f);
			PlaceFeature ("Forward shadows", new CGPoint (8, -1), 0.7f);
			PlaceFeature ("Snapshot", new CGPoint (6, -2), 0.75f);
			PlaceFeature ("Physics Fields", new CGPoint (-6, -3), 0.8f);
			PlaceFeature ("Archiving", new CGPoint (-11, 3), 0.9f);
			PlaceFeature ("Performance tools", new CGPoint (-2, -5), 1);
		}
Пример #9
0
        private SCNNode Level2Outline()
        {
            var floor = SCNShape.Create(MosconeFloor(), 10.0f * 1.01f);

            floor.ChamferRadius  = 10.0f;
            floor.ChamferProfile = OutlineChamferProfilePath();
            floor.ChamferMode    = SCNChamferMode.Front;

            // Use a transparent material for everything except the chamfer. That way only the outline of the model will be visible.
            var outlineMaterial = SCNMaterial.Create();

            outlineMaterial.Ambient.Contents  = outlineMaterial.Diffuse.Contents = outlineMaterial.Specular.Contents = NSColor.Black;
            outlineMaterial.Emission.Contents = NSColor.White;

            var tranparentMaterial = SCNMaterial.Create();

            tranparentMaterial.Transparency = 0.0f;

            var node = SCNNode.Create();

            node.Geometry           = floor;
            node.Geometry.Materials = new SCNMaterial[] {
                tranparentMaterial,
                tranparentMaterial,
                tranparentMaterial,
                outlineMaterial,
                outlineMaterial
            };

            return(node);
        }
Пример #10
0
        private static SCNGeometry CreateGeometry(nfloat width, nfloat length, string imagePath)
        {
            UIImage image    = null;
            var     material = new SCNMaterial();

            if (!string.IsNullOrEmpty(imagePath))
            {
                image = UIImage.FromFile(imagePath);
                material.Diffuse.Contents = image;
                //material.Diffuse.ContentColor
            }
            else
            {
                material.Diffuse.Contents = UIColor.White;
            }



            material.DoubleSided = true;

            var geometry = SCNPlane.Create(width, length);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #11
0
		public override void SetupSlide (PresentationViewController presentationViewController)
		{
			// Create the font and the materials that will be shared among the features in the word cloud
			Font = NSFont.FromFontName ("Myriad Set BoldItalic", 50) != null ? NSFont.FromFontName ("Myriad Set BoldItalic", 50) : NSFont.FromFontName ("Avenir Heavy Oblique", 50);

			var frontAndBackMaterial = SCNMaterial.Create ();
			var sideMaterial = SCNMaterial.Create ();
			sideMaterial.Diffuse.Contents = NSColor.DarkGray;

			Materials = new SCNMaterial[] { frontAndBackMaterial, sideMaterial, frontAndBackMaterial };

			// Add different features to the word cloud
			PlaceFeature ("Export to DAE", new CGPoint (10, -8), 0);
			PlaceFeature ("OpenGL Core Profile", new CGPoint (-16, -7), 0.05f);
			PlaceFeature ("Warmup", new CGPoint (-12, -10), 0.1f);
			PlaceFeature ("Constraints", new CGPoint (-10, 6), 0.15f);
			PlaceFeature ("Custom projection", new CGPoint (4, 9), 0.2f);
			PlaceFeature ("Skinning", new CGPoint (-4, 8), 0.25f);
			PlaceFeature ("Morphing", new CGPoint (-3, -8), 0.3f);
			PlaceFeature ("Performance Statistics", new CGPoint (-1, 6), 0.35f);
			PlaceFeature ("CIFilters", new CGPoint (1, 5), 0.85f);
			PlaceFeature ("GLKit Math", new CGPoint (3, -10), 0.45f);
			PlaceFeature ("Depth of Field", new CGPoint (-0.5f, 0), 0.47f);
			PlaceFeature ("Animation Events", new CGPoint (5, 3), 0.50f);
			PlaceFeature ("Shader Modifiers", new CGPoint (7, 2), 0.95f);
			PlaceFeature ("GOBO", new CGPoint (-10, 1), 0.60f);
			PlaceFeature ("Ray testing", new CGPoint (-8, 0), 0.65f);
			PlaceFeature ("Skybox", new CGPoint (8, -1), 0.7f);
			PlaceFeature ("Fresnel", new CGPoint (6, -2), 0.75f);
			PlaceFeature ("SCNShape", new CGPoint (-6, -3), 0.8f);
			PlaceFeature ("Levels of detail", new CGPoint (-11, 3), 0.9f);
			PlaceFeature ("Animation blending", new CGPoint (-2, -5), 1);
		}
Пример #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}");
            }
        }
        public virtual SCNNode CreateARPlaneNode(ARPlaneAnchor anchor, UIColor color)
        {
            Console.WriteLine($"ADD: {anchor.Alignment}, {anchor.Extent}");

            var material = new SCNMaterial();

            material.Diffuse.Contents = color;

            var geometry = new SCNPlane
            {
                Width     = anchor.Extent.X,
                Height    = anchor.Extent.Z,
                Materials = new[] { material, material, material, material },
            };

            var rotation = SCNMatrix4.Identity;

            SCNMatrix4.CreateRotationX((float)-Math.PI / 2.0f, out rotation);

            var planeNode = new SCNNode
            {
                Geometry    = geometry,
                Position    = new SCNVector3(anchor.Center.X, 0, anchor.Center.Z),
                Transform   = rotation,
                PhysicsBody = CreatePlanePhysics(geometry)
            };

            return(planeNode);
        }
Пример #14
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Create the font and the materials that will be shared among the features in the word cloud
            Font = NSFont.FromFontName("Myriad Set BoldItalic", 50) != null?NSFont.FromFontName("Myriad Set BoldItalic", 50) : NSFont.FromFontName("Avenir Heavy Oblique", 50);

            var frontAndBackMaterial = SCNMaterial.Create();
            var sideMaterial         = SCNMaterial.Create();

            sideMaterial.Diffuse.Contents = NSColor.DarkGray;

            Materials = new SCNMaterial[] { frontAndBackMaterial, sideMaterial, frontAndBackMaterial };

            // Add different features to the word cloud
            PlaceFeature("Export to DAE", new CGPoint(10, -8), 0);
            PlaceFeature("OpenGL Core Profile", new CGPoint(-16, -7), 0.05f);
            PlaceFeature("Warmup", new CGPoint(-12, -10), 0.1f);
            PlaceFeature("Constraints", new CGPoint(-10, 6), 0.15f);
            PlaceFeature("Custom projection", new CGPoint(4, 9), 0.2f);
            PlaceFeature("Skinning", new CGPoint(-4, 8), 0.25f);
            PlaceFeature("Morphing", new CGPoint(-3, -8), 0.3f);
            PlaceFeature("Performance Statistics", new CGPoint(-1, 6), 0.35f);
            PlaceFeature("CIFilters", new CGPoint(1, 5), 0.85f);
            PlaceFeature("GLKit Math", new CGPoint(3, -10), 0.45f);
            PlaceFeature("Depth of Field", new CGPoint(-0.5f, 0), 0.47f);
            PlaceFeature("Animation Events", new CGPoint(5, 3), 0.50f);
            PlaceFeature("Shader Modifiers", new CGPoint(7, 2), 0.95f);
            PlaceFeature("GOBO", new CGPoint(-10, 1), 0.60f);
            PlaceFeature("Ray testing", new CGPoint(-8, 0), 0.65f);
            PlaceFeature("Skybox", new CGPoint(8, -1), 0.7f);
            PlaceFeature("Fresnel", new CGPoint(6, -2), 0.75f);
            PlaceFeature("SCNShape", new CGPoint(-6, -3), 0.8f);
            PlaceFeature("Levels of detail", new CGPoint(-11, 3), 0.9f);
            PlaceFeature("Animation blending", new CGPoint(-2, -5), 1);
        }
        /// <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);
        }
Пример #16
0
        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);
        }
Пример #17
0
 public void SCNMaterial_ShaderModifierTest_Weak()
 {
     if (IntPtr.Size == 8)             // API is 64-bit only
     {
         SCNMaterial m = new SCNMaterial();
         m.WeakShaderModifiers = new NSDictionary();
     }
 }
Пример #18
0
 public void SCNMaterial_ShaderModifierTest()
 {
     if (IntPtr.Size == 8)             // API is 64-bit only
     {
         SCNMaterial m = new SCNMaterial();
         m.ShaderModifiers = new SCNShaderModifiers();
     }
 }
Пример #19
0
 public Material(Vector4 color, double roughness, double metalness)
 {
     SCNMaterial = SCNMaterial.Create();
     SCNMaterial.LightingModelName      = SCNLightingModel.PhysicallyBased;
     SCNMaterial.Diffuse.ContentColor   = NSColor.FromRgba(color.X, color.Y, color.Z, color.W);
     SCNMaterial.Roughness.ContentColor = NSColor.FromWhite((float)roughness, 1);
     SCNMaterial.Metalness.ContentColor = NSColor.FromWhite((float)metalness, 1);
 }
Пример #20
0
        private SCNMaterial TextSideAndChamferMaterial()
        {
            var material = SCNMaterial.Create();

            material.Diffuse.Contents     = NSColor.White;
            material.Reflective.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg"));
            material.Reflective.Intensity = 0.4f;
            return(material);
        }
Пример #21
0
        public static SCNMaterial Create(NSObject diffuse)
        {
            var material = SCNMaterial.Create();

            material.Diffuse.Contents  = diffuse;
            material.DoubleSided       = true;
            material.LightingModelName = SCNLightingModel.PhysicallyBased;

            return(material);
        }
Пример #22
0
        private SCNMaterial TextFrontMaterial()
        {
            var material = SCNMaterial.Create();

            material.Diffuse.Contents     = NSColor.Black;
            material.Reflective.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg"));
            material.Reflective.Intensity = 0.5f;
            material.Multiply.Contents    = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/gradient2", "tiff"));
            return(material);
        }
Пример #23
0
        private void ChangeFaceColour(SCNNode faceGeometry, UIColor colour)
        {
            var material = new SCNMaterial();
            var lips     = UIImage.FromBundle("lipsTemplate");

            material.Diffuse.Contents = lips;
            material.Ambient.Contents = UIColor.Red;
            //material.FillMode = SCNFillMode.Fill;

            faceGeometry.Geometry.FirstMaterial = material;
        }
Пример #24
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);
                }
            }
        }
Пример #25
0
        private static SCNGeometry CreateGeometry(float size, UIColor color)
        {
            var geometry = SCNBox.Create(size, size, size, 0);
            var material = new SCNMaterial();

            material.Diffuse.Contents = color;

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #26
0
        SCNGeometry CreateGeometry(float width, float height, float length, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNPyramid geometry = SCNPyramid.Create(width, height, length);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #27
0
        SCNGeometry CreateGeometry(float topRadius, float bottomRadius, float height, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNCone geometry = SCNCone.Create(topRadius, bottomRadius, height);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #28
0
        SCNGeometry CreateGeometry(float ringRadius, float pipeRadius, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNTorus geometry = SCNTorus.Create(ringRadius, pipeRadius);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #29
0
        SCNGeometry CreateGeometry(float radius, float height, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNCylinder geometry = SCNCylinder.Create(radius, height);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #30
0
        SCNGeometry CreateGeometry(float size, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNSphere geometry = SCNSphere.Create(size);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #31
0
        SCNGeometry CreateGeometry(float innerRadius, float outerRadius, float height, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNTube geometry = SCNTube.Create(innerRadius, outerRadius, height);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #32
0
        private static SCNBox CreateGeometry(ARPlaneAnchor planeAnchor)
        {
            var geometry       = SCNBox.Create(planeAnchor.Extent.X, PlaneHeight, planeAnchor.Extent.Z, 0);
            var topMaterial    = new SCNMaterial();
            var bottomMaterial = new SCNMaterial();

            topMaterial.Diffuse.Contents    = UIColor.FromRGBA(255, 255, 255, 20);
            bottomMaterial.Diffuse.Contents = UIColor.Black;

            geometry.Materials = new[] { topMaterial, bottomMaterial, bottomMaterial, bottomMaterial };

            return(geometry);
        }
Пример #33
0
        SCNGeometry CreateGeometry(float width, float length, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;
            material.DoubleSided      = true;

            SCNPlane geometry = SCNPlane.Create(width, length);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #34
0
        private static SCNGeometry CreateGeometry(float width, float length, SKScene videoScene)
        {
            var material = new SCNMaterial();

            material.Diffuse.Contents = videoScene;
            material.DoubleSided      = true;

            var geometry = SCNPlane.Create(width, length);

            geometry.Materials = new[] { material };

            return(geometry);
        }
Пример #35
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;
		}
		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);
			}
		}
Пример #37
0
		// the material to use for text
		SCNMaterial TextMaterial ()
		{
			if (Material == null) {
				Material = SCNMaterial.Create ();
				Material.Specular.Contents = SKColorHelper.FromCommonWhiteAlpha (0.6f, 1);
				#if __IOS__
				Material.Reflective.Contents = new UIImage ("images/color_envmap.png");
				#else
				Material.Reflective.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/color_envmap", "png"));
				#endif
				Material.Shininess = 0.1f;
			}
			return Material;
		}
		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);
		}
		private void AddPrimitive (SCNGeometry geometry, float yPos, CABasicAnimation rotationAnimation, SCNMaterial sharedMaterial)
		{
			var xPos = 13.0f * NMath.Sin (NMath.PI * 2 * PrimitiveIndex / 9.0f);
			var zPos = 13.0f * NMath.Cos (NMath.PI * 2 * PrimitiveIndex / 9.0f);

			var node = SCNNode.Create ();
			node.Position = new SCNVector3 (xPos, yPos, zPos);
			node.Geometry = geometry;
			node.Geometry.FirstMaterial = sharedMaterial;
			CarouselNode.AddChildNode (node);

			PrimitiveIndex++;
			rotationAnimation.TimeOffset = -PrimitiveIndex;
			node.AddAnimation (rotationAnimation, new NSString ("rotationAnimation"));
		}