Пример #1
0
        private void AddCone()
        {
            SCNNode coneNode = new SCNNode();

            coneNode.Geometry = SCNCone.Create(0.01f, (0.05f / 2), 0.05f * 2);
            coneNode.Geometry.FirstMaterial.Diffuse.Contents  = UIColor.SystemPinkColor; //Color del objeto
            coneNode.Geometry.FirstMaterial.Specular.Contents = UIColor.White;           //Color del reflejo
            coneNode.Position = new SCNVector3(0, 0, -0.1f);

            sceneView.Scene.RootNode.AddChildNode(coneNode);
        }
Пример #2
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);
        }
        private SCNNode CreateEyeNode()
        {
            // Create A Node To Represent The Eye
            var eyeGeometry = SCNCone.Create(0.005f, 0, 0.2f);

            eyeGeometry.RadialSegmentCount             = 3;
            eyeGeometry.FirstMaterial.Diffuse.Contents = UIColor.Green;
            //eyeGeometry.FirstMaterial.Transparency = 0.5f;

            // Create A Holder Node & Rotate It So The Gemoetry Points Towards The Device
            SCNNode node = SCNNode.FromGeometry(eyeGeometry);

            node.EulerAngles = new SCNVector3((float)-Math.PI / 2, node.EulerAngles.Y, node.EulerAngles.Z);

            node.Position = new SCNVector3(node.Position.X, node.Position.Y, 0.1f);

            SCNNode parentNode = new SCNNode();

            parentNode.AddChildNode(node);

            return(parentNode);
        }
Пример #4
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);
        }
Пример #5
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                break;

            case 1:
                TextManager.HighlightBullet(0);

                StaticShadowNode.Opacity = 1;

                var node = TextManager.AddCode("#aMaterial.#multiply#.contents = aShadowMap;#");
                node.Position = new SCNVector3(node.Position.X, node.Position.Y - 4, node.Position.Z);
                foreach (var child in node.ChildNodes)
                {
                    child.RenderingOrder = 1;
                    foreach (var m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                    }
                }
                break;

            case 2:
                //move the tree
                PalmTree.RunAction(SCNAction.RotateBy(0, NMath.PI * 4, 0, 8));
                break;

            case 3:
                TextManager.FadesIn = true;
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.AddEmptyLine();

                node = TextManager.AddCode("#aLight.#castsShadow# = YES;#");
                foreach (SCNNode child in node.ChildNodes)
                {
                    child.RenderingOrder = 1;
                    foreach (SCNMaterial m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                        m.WritesToDepthBuffer  = false;
                    }
                }

                node.Position = new SCNVector3(node.Position.X, node.Position.Y - 6, node.Position.Z);

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.75f;

                var spot = presentationViewController.SpotLight;
                OldSpotShadowColor      = spot.Light.ShadowColor;
                spot.Light.ShadowColor  = NSColor.Black;
                spot.Light.ShadowRadius = 3;

                var tp = TextManager.TextNode.Position;

                var superNode = presentationViewController.CameraNode.ParentNode.ParentNode;

                var p0 = GroundNode.ConvertPositionToNode(SCNVector3.Zero, null);
                var p1 = GroundNode.ConvertPositionToNode(new SCNVector3(20, 0, 0), null);
                var tr = new SCNVector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);

                var p = superNode.Position;
                p.X  += tr.X;
                p.Y  += tr.Y;
                p.Z  += tr.Z;
                tp.X += 20;
                tp.Y += 0;
                tp.Z += 0;
                superNode.Position            = p;
                TextManager.TextNode.Position = tp;
                SCNTransaction.Commit();

                TextManager.HighlightBullet(1);

                break;

            case 4:
                //move the light
                var lightPivot = SCNNode.Create();
                lightPivot.Position = Character.Position;
                GroundNode.AddChildNode(lightPivot);

                spot            = presentationViewController.SpotLight;
                OldSpotPosition = spot.Position;
                OldSpotParent   = spot.ParentNode;
                OldSpotZNear    = spot.Light.ZNear;

                spot.Light.ZNear = 20;
                spot.Position    = lightPivot.ConvertPositionFromNode(spot.Position, spot.ParentNode);
                lightPivot.AddChildNode(spot);

                //add an object to represent the light
                var lightModel  = SCNNode.Create();
                var lightHandle = SCNNode.Create();
                var cone        = SCNCone.Create(0, 0.5f, 1);
                cone.RadialSegmentCount = 10;
                cone.HeightSegmentCount = 5;
                lightModel.Geometry     = cone;
                lightModel.Geometry.FirstMaterial.Emission.Contents = NSColor.Yellow;
                lightHandle.Position   = new SCNVector3(spot.Position.X * DIST, spot.Position.Y * DIST, spot.Position.Z * DIST);
                lightModel.CastsShadow = false;
                lightModel.EulerAngles = new SCNVector3(NMath.PI / 2, 0, 0);
                lightHandle.AddChildNode(lightModel);
                lightHandle.Constraints = new SCNConstraint[] { SCNLookAtConstraint.Create(Character) };
                lightPivot.AddChildNode(lightHandle);
                LightHandle = lightHandle;

                var animation = CABasicAnimation.FromKeyPath("eulerAngles.z");
                animation.From           = new NSNumber((nfloat)(Math.PI / 4) * 1.7f);
                animation.To             = new NSNumber((nfloat)(-Math.PI / 4) * 0.3f);
                animation.Duration       = 4;
                animation.AutoReverses   = true;
                animation.RepeatCount    = float.MaxValue;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimeOffset     = animation.Duration / 2;
                lightPivot.AddAnimation(animation, new NSString("lightAnim"));
                break;

            case 5:
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                var text = TextManager.AddCode("#aLight.#shadowMode# =\n#SCNShadowModeModulated#;\naLight.#gobo# = anImage;#");
                text.Position = new SCNVector3(text.Position.X, text.Position.Y - 6, text.Position.Z);
                text.EnumerateChildNodes((SCNNode child, out bool stop) => {
                    stop = false;
                    child.RenderingOrder = 1;
                    foreach (var m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                        m.WritesToDepthBuffer  = false;
                    }
                    return(stop);
                });

                LightHandle.RemoveFromParentNode();

                RestoreSpotPosition(presentationViewController);
                TextManager.HighlightBullet(2);


                spot = presentationViewController.SpotLight;
                spot.Light.CastsShadow = false;

                var head = Character.FindChildNode("Bip001_Pelvis", true);

                node                      = SCNNode.Create();
                node.Light                = SCNLight.Create();
                node.Light.LightType      = SCNLightType.Spot;
                node.Light.SpotOuterAngle = 30;
                node.Constraints          = new SCNConstraint[] { SCNLookAtConstraint.Create(head) };
                node.Position             = new SCNVector3(0, 220, 0);
                node.Light.ZNear          = 10;
                node.Light.ZFar           = 1000;
                node.Light.Gobo.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/blobShadow", "jpg"));
                node.Light.Gobo.Intensity = 0.65f;
                node.Light.ShadowMode     = SCNShadowMode.Modulated;

                //exclude character from shadow
                node.Light.CategoryBitMask = 0x1;
                Character.FindNodes((SCNNode child, out bool stop) => {
                    stop = false;
                    child.CategoryBitMask = 0x2;
                    return(stop);
                });

                Projector = node;
                Character.AddChildNode(node);

                break;
            }
        }