Exemple #1
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1;

            switch (index)
            {
            case 0:
                break;

            case 1:
                //add a plan in the background
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.FadeOutText(SlideTextManager.TextType.Subtitle);

                var bg    = SCNNode.Create();
                var plane = SCNPlane.Create(100, 100);
                bg.Geometry = plane;
                bg.Position = new SCNVector3(0, 0, -60);
                presentationViewController.CameraNode.AddChildNode(bg);

                ((SCNView)presentationViewController.View).Scene.FogColor         = NSColor.White;
                ((SCNView)presentationViewController.View).Scene.FogStartDistance = 10;
                ((SCNView)presentationViewController.View).Scene.FogEndDistance   = 50;
                break;

            case 2:
                ((SCNView)presentationViewController.View).Scene.FogDensityExponent = 0.3f;
                break;
            }

            SCNTransaction.Commit();
        }
Exemple #2
0
        public static SCNPlane CreatePlane(CGSize size, NSObject contents)
        {
            var plane = SCNPlane.Create(size.Width, size.Height);

            plane.InsertMaterial(SCNMaterialExtensions.CreateMaterial(contents), 0);
            return(plane);
        }
Exemple #3
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);
        }
Exemple #4
0
        private SCNNode GetFillPlane()
        {
            var length = 1f - 2f * BorderSegment.Thickness;
            var plane  = SCNPlane.Create(length, length * this.AspectRatio);
            var node   = SCNNode.FromGeometry(plane);

            node.Name    = "fillPlane";
            node.Opacity = 0.6f;

            var material = plane.FirstMaterial;

            material.Diffuse.Contents = UIImage.FromBundle("art.scnassets/textures/grid.png");

            var textureScale = SimdExtensions.CreateFromScale(new SCNVector3(40f, 40f * this.AspectRatio, 1f));

            material.Diffuse.ContentsTransform  = textureScale;
            material.Emission.Contents          = UIImage.FromBundle("art.scnassets/textures/grid.png");
            material.Emission.ContentsTransform = textureScale;
            material.Diffuse.WrapS     = SCNWrapMode.Repeat;
            material.Diffuse.WrapT     = SCNWrapMode.Repeat;
            material.DoubleSided       = true;
            material.Ambient.Contents  = UIColor.Black;
            material.LightingModelName = SCNLightingModel.Constant;

            return(node);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
        private void HandleTap(UIGestureRecognizer gestureRecognize)
        {
            // Get current frame
            var currentFrame = SceneView.Session.CurrentFrame;

            if (currentFrame == null)
            {
                return;
            }

            // Create an image plane using a snapshot of the view
            var imagePlane = SCNPlane.Create(SceneView.Bounds.Width / 6000, SceneView.Bounds.Height / 6000);

            imagePlane.FirstMaterial.Diffuse.Contents  = SceneView.Snapshot();
            imagePlane.FirstMaterial.LightingModelName = SCNLightingModel.Constant;

            // Create a plane node and add it to the scene
            var planeNode = SCNNode.FromGeometry(imagePlane);

            SceneView.Scene.RootNode.AddChildNode(planeNode);

            // Set transform of node to be 10cm in front of the camera
            var translation       = SCNMatrix4.CreateTranslation(0, 0, 0.1f);
            var cameraTranslation = currentFrame.Camera.Transform.ToSCNMatrix4();

            planeNode.Transform = SCNMatrix4.Mult(cameraTranslation, translation);
        }
Exemple #8
0
        public static SCNPlane CreateSquarePlane(float size, NSObject contents)
        {
            var plane = SCNPlane.Create(size, size);

            plane.InsertMaterial(SCNMaterialExtensions.CreateMaterial(contents), 0);
            return(plane);
        }
Exemple #9
0
        private SCNNode GetFrameNode(SCNNode node, nfloat frameWidth)
        {
            node.Geometry.

            var plane = SCNPlane.Create(width + (2 * frameWidth), height + (2 * frameWidth));

            var planeNode = SCNNode.Create();

            planeNode.Geometry = plane;
            //planeNode.Geometry.FirstMaterial.Diffuse.Contents = UIColor.Blue;

            /*
             * `SCNPlane` is vertically oriented in its local coordinate space, but
             * `ARImageAnchor` assumes the image is horizontal in its local space, so
             * rotate the plane to match.
             */
            var EulerY = planeNode.EulerAngles.Y;
            var EulerZ = planeNode.EulerAngles.Z;

            planeNode.EulerAngles = new SCNVector3((float)-3.1416 / 2, EulerY, EulerZ);


            var frameSidePlane = SCNPlane.Create(0.01f, height);
            var planeSideNode  = SCNNode.Create();

            planeSideNode.Geometry = frameSidePlane;
            planeSideNode.Geometry.FirstMaterial.Diffuse.Contents = UIColor.Green;
            planeNode.Position = new SCNVector3(0, 0, 0);

            planeNode.Add(planeSideNode);


            return(planeNode);
        }
Exemple #10
0
        private void AddPlane()
        {
            SCNNode planeNode = new SCNNode();

            planeNode.Geometry = SCNPlane.Create(0.05f, 0.05f);
            planeNode.Geometry.FirstMaterial.Diffuse.Contents  = UIColor.Green; //Color del objeto
            planeNode.Geometry.FirstMaterial.Specular.Contents = UIColor.White; //Color del reflejo
            planeNode.Position = new SCNVector3(0, 0.1f, 0.1f);

            sceneView.Scene.RootNode.AddChildNode(planeNode);
        }
Exemple #11
0
        private SCNNode CreateLavaNode(ARPlaneAnchor planeAnchor)
        {
            SCNNode lavaNode = new SCNNode();

            lavaNode.Geometry = SCNPlane.Create(planeAnchor.Extent.X, planeAnchor.Extent.Z);
            lavaNode.Geometry.FirstMaterial.Diffuse.Contents = new UIImage("Lava.png");
            lavaNode.Geometry.FirstMaterial.DoubleSided      = true;
            lavaNode.Position    = new SCNVector3(planeAnchor.Center.X, planeAnchor.Center.Y, planeAnchor.Center.Z);
            lavaNode.EulerAngles = new SCNVector3(ConvertDegreesToRadians(90), 0, 0);

            return(lavaNode);
        }
Exemple #12
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            TextManager.SetTitle("Shadows");

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

            var sceneryHolder = SCNNode.Create();

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

            GroundNode.AddChildNode(sceneryHolder);

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

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

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

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

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

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

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

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

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

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

            character.EulerAngles = new SCNVector3(0, NMath.PI / 2, NMath.PI / 2);
            character.Position    = new SCNVector3(20, 0, 7);
            Character             = character;
        }
Exemple #13
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);
        }
Exemple #14
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);
        }
Exemple #15
0
        private static SCNPlane CreateGeometry(ARPlaneAnchor planeAnchor, UIColor colour)
        {
            var material = new SCNMaterial();

            material.Diffuse.Contents = colour;
            material.DoubleSided      = true;
            material.Transparency     = 0.8f;

            var geometry = SCNPlane.Create(planeAnchor.Extent.X, planeAnchor.Extent.Z);

            geometry.Materials = new[] { material };

            return(geometry);
        }
        /// <summary>
        /// Creates a plane an place in on the center of the plane anchor
        /// and rotates so it lies flat
        /// </summary>
        private void PlaceAnchorNode(SCNNode node, ARPlaneAnchor anchor)
        {
            var plane = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z);

            var material = new SCNMaterial();

            material.Diffuse.Contents        = UIImage.FromFile("art.scnassets/PlaneGrid/grid.png");
            plane.Materials                  = new[] { material };
            plane.FirstMaterial.Transparency = 0.1f;

            var planeNode = SCNNode.FromGeometry(plane);

            planeNode.Position  = new SCNVector3(anchor.Center.X, 0.0f, anchor.Center.Z);
            planeNode.Transform = SCNMatrix4.CreateRotationX((float)(-Math.PI / 2.0));
            node.AddChildNode(planeNode);
        }
Exemple #17
0
        static SCNNode CreateIconImageNode(string imageName, CGSize size)
        {
            var image         = UIImage.FromBundle(imageName);
            var imageGeometry = SCNPlane.Create(size.Width, size.Height);

            imageGeometry.FirstMaterial.Diffuse.Contents     = image;
            imageGeometry.FirstMaterial.LightingModelName    = SCNLightingModel.Constant;
            imageGeometry.FirstMaterial.DoubleSided          = true;
            imageGeometry.FirstMaterial.ReadsFromDepthBuffer = false;
            imageGeometry.FirstMaterial.WritesToDepthBuffer  = false;
            var planeNode = new SCNNode
            {
                Geometry = imageGeometry
            };

            return(planeNode);
        }
Exemple #18
0
        private SCNNode CreateConcreteNode(ARPlaneAnchor planeAnchor)
        {
            SCNNode concreteNode = new SCNNode();

            concreteNode.Geometry = SCNPlane.Create(planeAnchor.Extent.X, planeAnchor.Extent.Z);
            concreteNode.Geometry.FirstMaterial.Diffuse.Contents = new UIImage("Concrete.png");
            concreteNode.Geometry.FirstMaterial.DoubleSided      = true;
            concreteNode.Position    = new SCNVector3(planeAnchor.Center.X, planeAnchor.Center.Y, planeAnchor.Center.Z);
            concreteNode.EulerAngles = new SCNVector3(ConvertDegreesToRadians(90), 0, 0);

            //TODO 4.1 Creando superficie
            SCNPhysicsBody staticBody = SCNPhysicsBody.CreateStaticBody();

            concreteNode.PhysicsBody = staticBody;

            return(concreteNode);
        }
Exemple #19
0
        internal Tile(SCNPlane plane)
        {
            base.Init();
            Geometry = plane;
            Opacity  = 0F;

            // Create a child node with another plane of the same size, but a darker color to stand out better
            // This helps users see captured tiles from the back.
            if (ChildNodes.Length == 0)
            {
                var innerPlane = SCNPlane.Create(plane.Width, plane.Height);
                innerPlane.Materials = new[] { Utilities.Material(Utilities.AppBrown.ColorWithAlpha(0.8F), false, false) };
                var innerNode = SCNNode.FromGeometry(innerPlane);
                innerNode.EulerAngles = new SCNVector3(0, (float)Math.PI, 0);
                AddChildNode(innerNode);
            }
        }
Exemple #20
0
        public Plane(ARPlaneAnchor anchor)
        {
            this.PlaneAnchor = anchor;

            var grid = UIImage.FromBundle("plane_grid2.png");

            this.PlaneGeometry = SCNPlane.Create(PlaneAnchor.Extent.X, PlaneAnchor.Extent.Z);
            this.PlaneNode     = SCNNode.FromGeometry(PlaneGeometry);

            PlaneGeometry.FirstMaterial.Transparency     = 0.5f;
            PlaneGeometry.FirstMaterial.Diffuse.Contents = grid;

            PlaneNode.Transform = SCNMatrix4.CreateRotationX((float)-Math.PI / 2);
            PlaneNode.Position  = new SCNVector3(PlaneAnchor.Center.X, 0, PlaneAnchor.Center.Z);

            AddChildNode(PlaneNode);
        }
Exemple #21
0
        static SCNNode CreateBackgroundPlaneNode(CGSize size, UIColor color, float radius)
        {
            var planeGeometry = SCNPlane.Create(size.Width, size.Height);

            planeGeometry.CornerRadius = radius;
            planeGeometry.FirstMaterial.Diffuse.Contents     = color;
            planeGeometry.FirstMaterial.LightingModelName    = SCNLightingModel.Constant;
            planeGeometry.FirstMaterial.DoubleSided          = true;
            planeGeometry.FirstMaterial.ReadsFromDepthBuffer = false;
            planeGeometry.FirstMaterial.WritesToDepthBuffer  = false;
            var planeNode = new SCNNode
            {
                Geometry = planeGeometry
            };

            return(planeNode);
        }
Exemple #22
0
        public static SCNNode SCPlaneNodeWithImage(NSImage image, nfloat size, bool isLit)
        {
            var node = SCNNode.Create();

            var factor = size / (nfloat)(Math.Max(image.Size.Width, image.Size.Height));

            node.Geometry = SCNPlane.Create(image.Size.Width * factor, image.Size.Height * factor);
            node.Geometry.FirstMaterial.Diffuse.Contents = image;

            //if we don't want the image to be lit, set the lighting model to "constant"
            if (!isLit)
            {
                node.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
            }

            return(node);
        }
Exemple #23
0
        public BorderSegment(Corner corner, Alignment alignment, CGSize borderSize) : base()
        {
            this.corner    = corner;
            this.alignment = alignment;

            this.plane      = SCNPlane.Create(BorderSegment.Thickness, BorderSegment.Thickness);
            this.borderSize = borderSize;

            var material = this.plane.FirstMaterial;

            material.Diffuse.Contents  = GameBoard.BorderColor;
            material.Emission.Contents = GameBoard.BorderColor;
            material.DoubleSided       = true;
            material.Ambient.Contents  = UIColor.Black;
            material.LightingModelName = SCNLightingModel.Constant;

            this.Geometry = this.plane;
            this.Opacity  = 0.8f;
        }
        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);
        }
Exemple #25
0
        private void SetupTiles()
        {
            IsBusyUpdatingTiles = true;

            // Determine number of rows and columns
            var numRows    = Math.Min(maxTileCount, (int)(Math.Ceiling(size.Height / maxTileSize)));
            var numColumns = Math.Min(maxTileCount, (int)(Math.Ceiling(size.Width / maxTileSize)));

            var newTiles = new List <Tile>();

            // Create updates tiles and lay them out
            for (var row = 0; row < numRows; row++)
            {
                for (var col = 0; col < numColumns; col++)
                {
                    var plane = SCNPlane.Create(size.Width / numColumns, size.Height / numRows);
                    plane.Materials = new[] { Utilities.Material(color, false, false) };

                    var xPos = -size.Width / 2 + plane.Width / 2 + col * plane.Width;
                    var yPos = size.Height / 2 - plane.Height / 2 - row * plane.Height;

                    var tileNode = new Tile(plane);
                    tileNode.Position = new SCNVector3((float)xPos, (float)yPos, 0);
                    newTiles.Add(tileNode);
                }
            }

            // Replace the nodes in the scene graph.
            foreach (var tile in Tiles)
            {
                tile.RemoveFromParentNode();
            }
            foreach (var tile in newTiles)
            {
                AddChildNode(tile);
            }
            Tiles = newTiles;

            sizeOnLastTileUpdate = size;
            IsBusyUpdatingTiles  = false;
        }
Exemple #26
0
            SCNNode MakePlane(ARAnchor anchor)
            {
                var planeAchor = anchor as ARPlaneAnchor;

                if (planeAchor == null)
                {
                    return(SCNNode.Create());
                }

                Console.WriteLine($"MakePlane ({planeAchor})");

                var geometry = SCNPlane.Create(planeAchor.Extent.X, planeAchor.Extent.Z);

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

                var gnode = SCNNode.FromGeometry(geometry);

                gnode.Position  = new SCNVector3(planeAchor.Center.X, 0, planeAchor.Center.Z);
                gnode.Transform = SCNMatrix4.CreateFromAxisAngle(SCNVector3.UnitX, (float)(Math.PI / 2));

                return(gnode);
            }
        SCNGeometry CreateGeometry(string resource, float width, float height)
        {
            UIImage image;

            if (resource.StartsWith("http"))
            {
                image = FromUrl(resource);
            }
            else
            {
                image = UIImage.FromFile(resource);
            }

            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = image;
            material.DoubleSided      = true; // Ensure geometry viewable from all angles

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

            geometry.Materials = new[] { material };
            return(geometry);
        }
            void AddPlaneNode(ARPlaneAnchor anchor, SCNNode node, NSObject contents)
            {
                var geometry = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z);
                var material = geometry.Materials.FirstOrDefault() ?? throw new Exception();

                switch (contents)
                {
                case SCNProgram program:
                    material.Program = program;
                    break;

                default:
                    material.Diffuse.Contents = contents;
                    break;
                }

                var planeNode = SCNNode.FromGeometry(geometry);

                SceneKit.SCNMatrix4.CreateFromAxisAngle(new SCNVector3(1, 0, 0), (float)(-Math.PI / 2.0), out var m4);
                planeNode.Transform = m4;

                DispatchQueue.MainQueue.DispatchAsync(() => node.AddChildNode(planeNode));
            }
Exemple #29
0
        private void AddHouse()
        {
            var pyramidNode = new SCNNode();

            pyramidNode.Geometry = SCNPyramid.Create(0.1f, 0.1f, 0.1f);
            pyramidNode.Geometry.FirstMaterial.Diffuse.Contents = UIColor.Red;
            pyramidNode.Position = new SCNVector3(0, 0, -0.2f);
            sceneView.Scene.RootNode.AddChildNode(pyramidNode);

            var boxNode = new SCNNode();

            boxNode.Geometry = SCNBox.Create(0.1f, 0.1f, 0.1f, 0);
            boxNode.Geometry.FirstMaterial.Diffuse.Contents = UIColor.Blue;
            boxNode.Position = new SCNVector3(0, -0.05f, 0);
            pyramidNode.AddChildNode(boxNode);

            var door = new SCNNode();

            door.Geometry = SCNPlane.Create(0.03f, 0.06f);
            door.Geometry.FirstMaterial.Diffuse.Contents = UIColor.Brown;
            door.Position = new SCNVector3(0, -0.02f, 0.051f);
            boxNode.AddChildNode(door);

            var window1 = new SCNNode();

            window1.Geometry = SCNPlane.Create(0.02f, 0.02f);
            window1.Geometry.FirstMaterial.Diffuse.Contents = UIColor.White;
            window1.Position = new SCNVector3(0.03f, 0.025f, 0.051f);
            boxNode.AddChildNode(window1);

            var window2 = new SCNNode();

            window2.Geometry = SCNPlane.Create(0.02f, 0.02f);
            window2.Geometry.FirstMaterial.Diffuse.Contents = UIColor.White;
            window2.Position = new SCNVector3(-0.03f, 0.025f, 0.051f);
            boxNode.AddChildNode(window2);
        }
Exemple #30
0
        // Create a carousel of 3D primitives
        private void PresentPrimitives()
        {
            // Create the carousel node. It will host all the primitives as child nodes.
            CarouselNode          = SCNNode.Create();
            CarouselNode.Position = new SCNVector3(0, 0.1f, -5);
            CarouselNode.Scale    = new SCNVector3(0, 0, 0);           // start infinitely small
            ContentNode.AddChildNode(CarouselNode);

            // Animate the scale to achieve a "grow" effect
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 1;
            CarouselNode.Scale = new SCNVector3(1, 1, 1);
            SCNTransaction.Commit();

            // Rotate the carousel forever
            var rotationAnimation = CABasicAnimation.FromKeyPath("rotation");

            rotationAnimation.Duration    = 40.0f;
            rotationAnimation.RepeatCount = float.MaxValue;
            rotationAnimation.To          = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)Math.PI * 2));
            CarouselNode.AddAnimation(rotationAnimation, new NSString("rotationAnimation"));

            // A material shared by all the primitives
            var sharedMaterial = SCNMaterial.Create();

            sharedMaterial.Reflective.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg"));
            sharedMaterial.Reflective.Intensity = 0.2f;
            sharedMaterial.DoubleSided          = true;

            PrimitiveIndex = 0;

            // SCNBox
            var box = SCNBox.Create(5.0f, 5.0f, 5.0f, 5.0f * 0.05f);

            box.WidthSegmentCount   = 4;
            box.HeightSegmentCount  = 4;
            box.LengthSegmentCount  = 4;
            box.ChamferSegmentCount = 4;
            AddPrimitive(box, 5.0f / 2, rotationAnimation, sharedMaterial);

            // SCNPyramid
            var pyramid = SCNPyramid.Create(5.0f * 0.8f, 5.0f, 5.0f * 0.8f);

            pyramid.WidthSegmentCount  = 4;
            pyramid.HeightSegmentCount = 10;
            pyramid.LengthSegmentCount = 4;
            AddPrimitive(pyramid, 0, rotationAnimation, sharedMaterial);

            // SCNCone
            var cone = SCNCone.Create(0, 5.0f / 2, 5.0f);

            cone.RadialSegmentCount = 20;
            cone.HeightSegmentCount = 4;
            AddPrimitive(cone, 5.0f / 2, rotationAnimation, sharedMaterial);

            // SCNTube
            var tube = SCNTube.Create(5.0f * 0.25f, 5.0f * 0.5f, 5.0f);

            tube.HeightSegmentCount = 5;
            tube.RadialSegmentCount = 40;
            AddPrimitive(tube, 5.0f / 2, rotationAnimation, sharedMaterial);

            // SCNCapsule
            var capsule = SCNCapsule.Create(5.0f * 0.4f, 5.0f * 1.4f);

            capsule.HeightSegmentCount = 5;
            capsule.RadialSegmentCount = 20;
            AddPrimitive(capsule, 5.0f * 0.7f, rotationAnimation, sharedMaterial);

            // SCNCylinder
            var cylinder = SCNCylinder.Create(5.0f * 0.5f, 5.0f);

            cylinder.HeightSegmentCount = 5;
            cylinder.RadialSegmentCount = 40;
            AddPrimitive(cylinder, 5.0f / 2, rotationAnimation, sharedMaterial);

            // SCNSphere
            var sphere = SCNSphere.Create(5.0f * 0.5f);

            sphere.SegmentCount = 20;
            AddPrimitive(sphere, 5.0f / 2, rotationAnimation, sharedMaterial);

            // SCNTorus
            var torus = SCNTorus.Create(5.0f * 0.5f, 5.0f * 0.25f);

            torus.RingSegmentCount = 40;
            torus.PipeSegmentCount = 20;
            AddPrimitive(torus, 5.0f / 4, rotationAnimation, sharedMaterial);

            // SCNPlane
            var plane = SCNPlane.Create(5.0f, 5.0f);

            plane.WidthSegmentCount  = 5;
            plane.HeightSegmentCount = 5;
            plane.CornerRadius       = 5.0f * 0.1f;
            AddPrimitive(plane, 5.0f / 2, rotationAnimation, sharedMaterial);
        }