private void PresentPrimitives(PresentationViewController presentationViewController)
        {
            var count  = 100;
            var spread = 0.0f;

            // create a cube with a sphere shape
            for (int i = 0; i < count; ++i)
            {
                var model = SCNNode.Create();
                model.Position    = GroundNode.ConvertPositionToNode(new SCNVector3(RandFloat(-1, 1), RandFloat(30, 50), RandFloat(-1, 1)), null);
                model.EulerAngles = new SCNVector3(RandFloat(0, NMath.PI * 2), RandFloat(0, NMath.PI * 2), RandFloat(0, NMath.PI * 2));

                var size          = new SCNVector3(RandFloat(1.0, 1.5), RandFloat(1.0, 1.5), RandFloat(1.0, 1.5));
                var random        = new Random((int)DateTime.Now.Ticks);
                int geometryIndex = random.Next(0, 7);
                switch (geometryIndex)
                {
                case 0:                 // Box
                    model.Geometry = SCNBox.Create(size.X, size.Y, size.Z, 0);
                    break;

                case 1:                 // Pyramid
                    model.Geometry = SCNPyramid.Create(size.X, size.Y, size.Z);
                    break;

                case 2:                 // Sphere
                    model.Geometry = SCNSphere.Create(size.X);
                    break;

                case 3:                 // Cylinder
                    model.Geometry = SCNCylinder.Create(size.X, size.Y);
                    break;

                case 4:                 // Tube
                    model.Geometry = SCNTube.Create(size.X, size.X + size.Z, size.Y);
                    break;

                case 5:                 // Capsule
                    model.Geometry = SCNCapsule.Create(size.X, size.Y + 2 * size.X);
                    break;

                case 6:                 // Torus
                    model.Geometry = SCNTorus.Create(size.X, NMath.Min(size.X, size.Y) / 2);
                    break;

                default:
                    break;
                }

                model.Geometry.FirstMaterial.Multiply.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/texture", "png"));

                model.PhysicsBody                 = SCNPhysicsBody.CreateDynamicBody();
                model.PhysicsBody.Velocity        = new SCNVector3(RandFloat(-spread, spread), -10, RandFloat(-spread, spread));
                model.PhysicsBody.AngularVelocity = new SCNVector4(RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-3, 3));

                Shapes.Add(model);

                ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(model);
            }
        }
Exemple #2
0
        private SCNGeometry Cylinder(double width, double height)
        {
            var cylinderGeometry = SCNCylinder.Create((nfloat)width / 2, (nfloat)height);
            var gradYellowMat    = Utilities.Material(UIImage.FromBundle("yellowimage"));
            var clearMaterial    = Utilities.Material(UIColor.Clear);

            cylinderGeometry.Materials = new[] { gradYellowMat, clearMaterial, clearMaterial };
            return(cylinderGeometry);
        }
        private SCNGeometry Cylinder(float height, float?width = null, UIColor colorArg = null)
        {
            var radius           = width == null ? (float)lineThickness / 2 : width.Value / 2;
            var clr              = colorArg ?? this.color;
            var cylinderGeometry = SCNCylinder.Create(radius, height);

            cylinderGeometry.Materials = new[] { Utilities.Material(clr) };
            return(cylinderGeometry);
        }
Exemple #4
0
        private void AddCylinder()
        {
            SCNNode cylinderNode = new SCNNode();

            cylinderNode.Geometry = SCNCylinder.Create(0.05f / 2, 0.05f);
            cylinderNode.Geometry.FirstMaterial.Diffuse.Contents  = UIColor.SystemPurpleColor; //Color del objeto
            cylinderNode.Geometry.FirstMaterial.Specular.Contents = UIColor.White;             //Color del reflejo
            cylinderNode.Position = new SCNVector3(0.1f, 0.1f, 0);

            sceneView.Scene.RootNode.AddChildNode(cylinderNode);
        }
        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);
        }
Exemple #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);
        }
Exemple #7
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);
        }
Exemple #8
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            // Animate by default
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0;

            switch (index)
            {
            case 0:
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);
                break;

            case 1:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddEmptyLine();
                TextManager.AddCode("#// Rotate forever\n"
                                    + "[aNode #runAction:#\n"
                                    + "  [SCNAction repeatActionForever:\n"
                                    + "  [SCNAction rotateByX:0 y:M_PI*2 z:0 duration:5.0]]];#");

                TextManager.FlipInText(SlideTextManager.TextType.Code);
                break;

            case 2:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.FlipOutText(SlideTextManager.TextType.Code);

                TextManager.AddBulletAtLevel("Move", 0);
                TextManager.AddBulletAtLevel("Rotate", 0);
                TextManager.AddBulletAtLevel("Scale", 0);
                TextManager.AddBulletAtLevel("Opacity", 0);
                TextManager.AddBulletAtLevel("Remove", 0);
                TextManager.AddBulletAtLevel("Wait", 0);
                TextManager.AddBulletAtLevel("Custom block", 0);

                TextManager.FlipInText(SlideTextManager.TextType.Bullet);
                break;

            case 3:
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.AddEmptyLine();
                TextManager.AddBulletAtLevel("Directly targets the render tree", 0);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);
                break;

            case 4:
                TextManager.AddBulletAtLevel("node.position / node.presentationNode.position", 0);

                //labels
                var label1 = TextManager.AddTextAtLevel("Action", 0);
                label1.Position = new SCNVector3(-15, 3, 0);
                var label2 = TextManager.AddTextAtLevel("Animation", 0);
                label2.Position = new SCNVector3(-15, -2, 0);

                //animation
                var animNode = SCNNode.Create();
                var cubeSize = 4.0f;
                animNode.Position = new SCNVector3(-5, cubeSize / 2, 0);

                var cube = SCNBox.Create(cubeSize, cubeSize, cubeSize, 0.05f * cubeSize);

                cube.FirstMaterial.Diffuse.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/texture", "png"));
                cube.FirstMaterial.Diffuse.MipFilter = SCNFilterMode.Linear;
                cube.FirstMaterial.Diffuse.WrapS     = SCNWrapMode.Repeat;
                cube.FirstMaterial.Diffuse.WrapT     = SCNWrapMode.Repeat;
                animNode.Geometry = cube;
                ContentNode.AddChildNode(animNode);

                SCNTransaction.Begin();


                SCNNode           animPosIndicator = null;
                SCNAnimationEvent startEvt         = SCNAnimationEvent.Create(0, (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0;
                    animPosIndicator.Position        = new SCNVector3(10, animPosIndicator.Position.Y, animPosIndicator.Position.Z);
                    SCNTransaction.Commit();
                });
                SCNAnimationEvent endEvt = SCNAnimationEvent.Create(1, (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                    SCNTransaction.Begin();
                    SCNTransaction.AnimationDuration = 0;
                    animPosIndicator.Position        = new SCNVector3(-5, animPosIndicator.Position.Y, animPosIndicator.Position.Z);
                    SCNTransaction.Commit();
                });

                var anim = CABasicAnimation.FromKeyPath("position.x");
                anim.Duration        = 3;
                anim.From            = new NSNumber(0.0);
                anim.To              = new NSNumber(15.0);
                anim.Additive        = true;
                anim.AutoReverses    = true;
                anim.AnimationEvents = new SCNAnimationEvent[] { startEvt, endEvt };
                anim.RepeatCount     = float.MaxValue;
                animNode.AddAnimation(anim, new NSString("cubeAnimation"));

                //action
                var actionNode = SCNNode.Create();
                actionNode.Position = new SCNVector3(-5, cubeSize * 1.5f + 1, 0);
                actionNode.Geometry = cube;

                ContentNode.AddChildNode(actionNode);

                var mv = SCNAction.MoveBy(15, 0, 0, 3);

                actionNode.RunAction(SCNAction.RepeatActionForever(SCNAction.Sequence(new SCNAction[] {
                    mv,
                    mv.ReversedAction()
                })));

                //position indicator
                var positionIndicator = SCNNode.Create();
                positionIndicator.Geometry = SCNCylinder.Create(0.5f, 0.01f);
                positionIndicator.Geometry.FirstMaterial.Diffuse.Contents  = NSColor.Red;
                positionIndicator.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
                positionIndicator.EulerAngles = new SCNVector3(NMath.PI / 2, 0, 0);
                positionIndicator.Position    = new SCNVector3(0, 0, cubeSize * 0.5f);
                actionNode.AddChildNode(positionIndicator);

                //anim pos indicator
                animPosIndicator          = positionIndicator.Clone();
                animPosIndicator.Position = new SCNVector3(5, cubeSize / 2, cubeSize * 0.5f);
                ContentNode.AddChildNode(animPosIndicator);

                SCNTransaction.Commit();

                break;
            }
            SCNTransaction.Commit();
        }