Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        private SCNNode NodeWithCode(string code)
        {
            // Node hierarchy:
            // codeNode
            // |__ regularCodeNode
            // |__ emphasis-0 (can be highlighted separately)
            // |__ emphasis-1 (can be highlighted separately)
            // |__ emphasis-2 (can be highlighted separately)
            // |__ ...

            var codeNode = SCNNode.Create();

            var chunk           = 0;
            var regularCode     = "";
            var whitespacesCode = "";

            // Automatically highlight the parts of the code that are delimited by '#'
            var components = code.Split('#');

            for (int i = 0; i < components.Length; i++)
            {
                var component = components [i];

                var whitespaces = "";
                for (int j = 0; j < component.Length; j++)
                {
                    string character = component.Substring(j, 1);
                    if (character == "\n")
                    {
                        whitespaces = whitespaces + "\n";
                    }
                    else
                    {
                        whitespaces = whitespaces + " ";
                    }
                }

                if ((i % 2) == 0)
                {
                    var emphasisedCodeNode = NodeWithText(whitespacesCode + component, TextType.Code, 1);
                    emphasisedCodeNode.Name = "emphasis-" + (chunk++);
                    codeNode.AddChildNode(emphasisedCodeNode);

                    regularCode = regularCode + whitespaces;
                }
                else
                {
                    regularCode = regularCode + component;
                }

                whitespacesCode = whitespacesCode + whitespaces;
            }

            var regularCodeNode = NodeWithText(regularCode, TextType.Code, 0);

            regularCodeNode.Name = "regular";
            codeNode.AddChildNode(regularCodeNode);

            return(codeNode);
        }
Beispiel #5
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Load the scene
            var intermediateNode = SCNNode.Create();

            intermediateNode.Position = new SCNVector3(6, 9, 0);
            intermediateNode.Scale    = new SCNVector3(1.4f, 1, 1);
            GroundNode.AddChildNode(intermediateNode);

            MapNode          = Utils.SCAddChildNode(intermediateNode, "Map", "Scenes/map/foldingMap", 25);
            MapNode.Position = new SCNVector3(0, 0, 0);
            MapNode.Opacity  = 0.0f;

            // Use a bunch of shader modifiers to simulate ambient occlusion when the map is folded
            var geomFile         = NSBundle.MainBundle.PathForResource("Shaders/mapGeometry", "shader");
            var fragFile         = NSBundle.MainBundle.PathForResource("Shaders/mapFragment", "shader");
            var lightFile        = NSBundle.MainBundle.PathForResource("Shaders/mapLighting", "shader");
            var geometryModifier = File.ReadAllText(geomFile);
            var fragmentModifier = File.ReadAllText(fragFile);
            var lightingModifier = File.ReadAllText(lightFile);

            MapNode.Geometry.ShaderModifiers = new SCNShaderModifiers {
                EntryPointGeometry      = geometryModifier,
                EntryPointFragment      = fragmentModifier,
                EntryPointLightingModel = lightingModifier
            };
        }
Beispiel #6
0
        public Slide()
        {
            ContentNode = SCNNode.Create();

            GroundNode = SCNNode.Create();
            ContentNode.AddChildNode(GroundNode);

            TextManager = new SlideTextManager();
            ContentNode.AddChildNode(TextManager.TextNode);

            // Default parameters
            LightIntensities    = new float[] { 1.0f };
            MainLightPosition   = new SCNVector3(0, 3, -13);
            EnableShadows       = false;
            FloorImageName      = null;
            FloorImageExtension = null;
            FloorReflectivity   = 0.25f;
            FloorFalloff        = 3.0f;
            TransitionDuration  = 1.0f;
            TransitionOffsetX   = 0.0f;
            TransitionOffsetZ   = 0.0f;
            TransitionRotation  = 0.0f;
            Altitude            = 5.0f;
            Pitch       = 0.0f;
            IsNewIn10_9 = false;
        }
Beispiel #7
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Create a node to own the "sign" model, make it to be close to the camera, rotate by 90 degree because it's oriented with z as the up axis
            var intermediateNode = SCNNode.Create();

            intermediateNode.Position = new SCNVector3(0, 0, 7);
            intermediateNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2));
            GroundNode.AddChildNode(intermediateNode);

            // Load the "sign" model
            var signNode = Utils.SCAddChildNode(intermediateNode, "sign", "Scenes/intersection/intersection", 30);

            signNode.Position = new SCNVector3(4, -2, 0.05f);

            // Re-parent every node that holds a camera otherwise they would inherit the scale from the "sign" model.
            // This is not a problem except that the scale affects the zRange of cameras and so it would be harder to get the transition from one camera to another right
            var cameraNodes = new NSMutableArray();

            foreach (SCNNode child in signNode)
            {
                if (child.Camera != null)
                {
                    cameraNodes.Add(child);
                }
            }

            for (nuint i = 0; i < cameraNodes.Count; i++)
            {
                var cameraNode             = new SCNNode(cameraNodes.ValueAt((uint)i));
                var previousWorldTransform = cameraNode.WorldTransform;
                intermediateNode.AddChildNode(cameraNode);                  // re-parent
                cameraNode.Transform = intermediateNode.ConvertTransformFromNode(previousWorldTransform, null);
                cameraNode.Scale     = new SCNVector3(1, 1, 1);
            }
        }
Beispiel #8
0
        void TapAction(UITapGestureRecognizer tap)
        {
            if (tap.State == UIGestureRecognizerState.Ended)
            {
                var tapLocation = tap.LocationInView(sceneView);
                var hitResults  = sceneView.HitTest(tapLocation, new NSDictionary());
                if (hitResults.Length != 0)
                {
                    var NodeResult = hitResults[0].Node;
                    if (NodeResult != null)
                    {
                        var nodeText = SCNText.Create(NodeResult.Name, 5);

                        var textNode = SCNNode.Create();
                        textNode.Geometry = nodeText;
                        textNode.Scale    = new SCNVector3(0.01f, 0.01f, 0.01f);
                        var min = new SCNVector3();
                        var max = new SCNVector3();
                        textNode.GetBoundingBox(ref min, ref max);

                        textNode.Position = new SCNVector3((textNode.Position.X - (textNode.Scale.X / 2)), textNode.Position.Y + 0.5f, textNode.Position.Z);
                        NodeResult.AddChildNode(textNode);
                    }
                }
            }
        }
Beispiel #9
0
        public void CreateLight()
        {
            float pi        = (float)Math.PI;
            var   light     = SCNLight.Create();
            var   lightNode = SCNNode.Create();

            light.LightType    = SCNLightType.Omni;
            light.Color        = UIColor.White;
            lightNode.Light    = light;
            lightNode.Position = new SCNVector3(-90, 40, 60);
            gameScene.RootNode.AddChildNode(lightNode);

            var directionLight = SCNNode.Create();

            directionLight.Light                 = SCNLight.Create();
            directionLight.Light.LightType       = SCNLightType.Directional;
            directionLight.Light.CastsShadow     = true;
            directionLight.Light.ShadowMode      = SCNShadowMode.Deferred;
            directionLight.Light.CategoryBitMask = (System.nuint)(-1);
            directionLight.Light.AutomaticallyAdjustsShadowProjection = true;
            directionLight.Light.MaximumShadowDistance = 50;
            directionLight.Position          = new SCNVector3(-90, 40, 60);
            directionLight.Rotation          = new SCNVector4(x: -1, y: 0, z: 0, w: pi / 2);
            directionLight.Light.ShadowColor = new UIColor(white: 0, alpha: 0.5f);

            gameScene.RootNode.AddChildNode(directionLight);
        }
        public override void ViewDidLoad()
        {
            Title = "ARKit";

            View = sceneView;

            sceneView.ShowsStatistics = true;
            sceneView.AutomaticallyUpdatesLighting = true;

            sceneView.Scene = SCNScene.Create();
            var root = sceneView.Scene.RootNode;

            var cameraNode = SCNNode.Create();

            cameraNode.Camera = SCNCamera.Create();
            root.AddChildNode(cameraNode);

            var lightNode = SCNNode.Create();

            cameraNode.Light = SCNLight.Create();
            root.AddChildNode(lightNode);

            var label = new UILabel(new CGRect(10, 10, 300, 30));

            View.AddSubview(label);
        }
Beispiel #11
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            // Set the slide's title and subtitle and add some text
            TextManager.SetTitle("Materials");
            TextManager.SetSubtitle("Property contents");

            TextManager.AddBulletAtLevel("Color", 0);
            TextManager.AddBulletAtLevel("CGColorRef / NSColor / UIColor", 0);

            var node = SCNNode.Create();

            node.Name     = "material-cube";
            node.Geometry = SCNBox.Create(W, W, W, W * 0.02f);

            Material = node.Geometry.FirstMaterial;
            Material.Diffuse.Contents = NSColor.Red;

            Object = node;

            node.Position = new SCNVector3(8, 11, 0);
            ContentNode.AddChildNode(node);
            node.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy((float)Math.PI * 2, new SCNVector3(0.4f, 1, 0), 4)));

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

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

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

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

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

            AnimatedNode.AddChildNode(torusNode);
            ContentNode.AddChildNode(AnimatedNode);
        }
Beispiel #13
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();
        }
        void CollectFlower(SCNNode node)
        {
            if (node.ParentNode == null)
            {
                return;
            }

            SCNNode soundEmitter = SCNNode.Create();

            soundEmitter.Position = node.Position;
            node.ParentNode.AddChildNode(soundEmitter);
            soundEmitter.RunAction(SCNAction.Sequence(new [] {
                SCNAction.PlayAudioSource(collectFlowerSound, true),
                SCNAction.RemoveFromParentNode()
            }));

            node.RemoveFromParentNode();

            // Check if game is complete.
            bool gameComplete = GameView.DidCollectAFlower();

            // Edit some particles.
            SCNMatrix4 particlePosition = soundEmitter.WorldTransform;

            particlePosition.M42 += 0.1f;
            GameView.Scene.AddParticleSystem(collectParticles, particlePosition);

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

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

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

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

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

            AnimatedNode.AddChildNode(torusNode);
            ContentNode.AddChildNode(AnimatedNode);
        }
Beispiel #16
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0;

            switch (index)
            {
            case 0:
                // Set the slide's title and subtile and add some text
                TextManager.SetTitle("Node Attributes");
                TextManager.SetSubtitle("Lights");

                TextManager.AddBulletAtLevel("SCNLight", 0);
                TextManager.AddBulletAtLevel("Four light types", 0);
                TextManager.AddBulletAtLevel("Omni", 1);
                TextManager.AddBulletAtLevel("Directional", 1);
                TextManager.AddBulletAtLevel("Spot", 1);
                TextManager.AddBulletAtLevel("Ambient", 1);
                break;

            case 1:
                // Add some code
                var codeExampleNode = TextManager.AddCode("#aNode.#Light# = SCNLight.Create (); \naNode.Light.LightType = SCNLightType.Omni;#");
                codeExampleNode.Position = new SCNVector3(14, 11, 1);

                // Add a light to the scene
                LightNode                 = SCNNode.Create();
                LightNode.Light           = SCNLight.Create();
                LightNode.Light.LightType = SCNLightType.Omni;
                LightNode.Light.Color     = NSColor.Black;             // initially off
                LightNode.Light.SetAttribute(new NSNumber(30), SCNLightAttribute.AttenuationStartKey);
                LightNode.Light.SetAttribute(new NSNumber(40), SCNLightAttribute.AttenuationEndKey);
                LightNode.Position = new SCNVector3(5, 3.5f, 0);
                ContentNode.AddChildNode(LightNode);

                // Load two images to help visualize the light (on and off)
                LightOffImageNode        = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-off", "tiff"), 7, false);
                LightOnImageNode         = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-on", "tiff"), 7, false);
                LightOnImageNode.Opacity = 0;

                LightNode.AddChildNode(LightOnImageNode);
                LightNode.AddChildNode(LightOffImageNode);
                break;

            case 2:
                // Switch the light on
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                LightNode.Light.Color            = NSColor.FromCalibratedRgba(1, 1, 0.8f, 1);
                LightOnImageNode.Opacity         = 1.0f;
                LightOffImageNode.Opacity        = 0.0f;
                SCNTransaction.Commit();
                break;
            }
            SCNTransaction.Commit();
        }
        void SetupCamera()
        {
            SCNNode     pov      = GameView.PointOfView;
            const float altitude = 1f;
            const float distance = 10f;

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

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

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

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

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

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

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

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

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

            SCNTransaction.Commit();

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

            lookAtConstraint.InfluenceFactor = 0;
            pov.Constraints = new SCNConstraint[] { lookAtConstraint };
        }
Beispiel #18
0
        private SCNNode CreatePoolBall(SCNVector3 position)
        {
            var model = SCNNode.Create();

            model.Position = position;
            model.Geometry = SCNSphere.Create(0.7f);
            model.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Scenes.scnassets/pool/pool_8", "png"));
            model.PhysicsBody = SCNPhysicsBody.CreateDynamicBody();
            return(model);
        }
Beispiel #19
0
            public override SCNNode GetNode(ISCNSceneRenderer renderer, ARAnchor anchor)
            {
                Console.WriteLine($"GetNode ({renderer}, {anchor})");

                var node = SCNNode.Create();

                node.Add(MakeBox(anchor));

                return(node);
            }
        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);
                }
            }
        }
Beispiel #21
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;
        }
Beispiel #22
0
        public void LoadModal()
        {
            var scene = SCNScene.FromFile("art.scnassets/ship.scn");

            var wrapperNode = SCNNode.Create();

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

            this.AddChildNode(wrapperNode);
        }
Beispiel #23
0
        private void SetupInvironment(SCNScene scene)
        {
            var ambientLight = SCNNode.Create();

            ambientLight.Light = new SCNLight {
                LightType = SCNLightType.Ambient,
                Color     = UIColor.FromWhiteAlpha(0.3f, 1f)
            };
            scene.RootNode.AddChildNode(ambientLight);

            var lightNode = new SCNNode {
                Position = new SCNVector3(0f, 80f, 30f),
                Rotation = new SCNVector4(1f, 0f, 0f, (float)(-Math.PI / 2.8))
            };

            lightNode.Light = new SCNLight {
                LightType      = SCNLightType.Spot,
                Color          = UIColor.FromWhiteAlpha(0.8f, 1f),
                SpotInnerAngle = 0f,
                SpotOuterAngle = 50f,
                ShadowColor    = UIColor.Black,
                ZFar           = 500f,
                ZNear          = 50f
            };

            if (IsHighEndDevice)
            {
                ambientLight.Light.CastsShadow = true;
            }

            scene.RootNode.AddChildNode(lightNode);

            spotLightNode = lightNode;

            var floor = SCNNode.Create();

            floor.Geometry = new SCNFloor();
            floor.Geometry.FirstMaterial.Diffuse.Contents          = ResourceManager.GetResourcePath("wood.png");
            floor.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Scale(2f, 2f, 1f);
            floor.Geometry.FirstMaterial.LocksAmbientWithDiffuse   = true;

            if (IsHighEndDevice)
            {
                ((SCNFloor)floor.Geometry).ReflectionFalloffEnd = 10f;
            }

            var staticBody = SCNPhysicsBody.CreateStaticBody();

            floor.PhysicsBody = staticBody;
            scene.RootNode.AddChildNode(floor);
        }
Beispiel #24
0
        public void AddAnimation_Overload()
        {
            TestRuntime.AssertXcodeVersion(9, 0);

            using (var ca = CAAnimation.CreateAnimation())
                using (var a = SCNAnimation.FromCAAnimation(ca))
                    using (var n = SCNNode.Create()) {
                        n.AddAnimation(a, "key");
                        n.RemoveAllAnimations();

                        n.AddAnimation(a, null);
                        n.RemoveAllAnimations();
                    }
        }
Beispiel #25
0
        private SCNNode CreateBlock(SCNVector3 position, SCNVector3 size)
        {
            if (DiceMesh == null)
            {
                DiceMesh = CreateBlockMesh(size);
            }

            var model = SCNNode.Create();

            model.Position    = position;
            model.Geometry    = DiceMesh;
            model.PhysicsBody = SCNPhysicsBody.CreateDynamicBody();

            return(model);
        }
Beispiel #26
0
        public void AddAnimation()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);

            using (var a = CAAnimation.CreateAnimation())
                using (var n = SCNNode.Create()) {
                    n.AddAnimation(a, (NSString)null);
                    n.AddAnimation(a, (string)null);
                    string key = "key";
                    n.AddAnimation(a, key);
                    using (var s = new NSString(key))
                        n.AddAnimation(a, s);
                }
        }
Beispiel #27
0
        private void AddPrimitive(SCNGeometry geometry, float yPos, CABasicAnimation rotationAnimation, SCNMaterial sharedMaterial)
        {
            var xPos = 13.0f * (float)Math.Sin((float)Math.PI * 2 * PrimitiveIndex / 9.0f);
            var zPos = 13.0f * (float)Math.Cos((float)Math.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"));
        }
Beispiel #28
0
        public void SCNNode_SetPhysicsBodyTest()
        {
            Asserts.EnsureYosemite();

            if (IntPtr.Size == 8)
            {
                // Create a new empty scene
                var Scene = new SCNScene();

                var floorNode = SCNNode.Create();
                Scene.RootNode.AddChildNode(floorNode);

                floorNode.PhysicsBody    = SCNPhysicsBody.CreateStaticBody();
                Scene.PhysicsWorld.Speed = 0;
            }
        }
Beispiel #29
0
        public override void SetupSlide(PresentationViewController presentationViewController)
        {
            TextManager.SetTitle("Depth of Field");
            TextManager.SetSubtitle("SCNCamera");

            // Create a node that will contain the chess board
            var intermediateNode = SCNNode.Create();

            intermediateNode.Scale    = new SCNVector3(35.0f, 35.0f, 35.0f);
            intermediateNode.Position = new SCNVector3(0, 2.1f, 20);
            intermediateNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2));
            ContentNode.AddChildNode(intermediateNode);

            // Load the chess model and add to "intermediateNode"
            Utils.SCAddChildNode(intermediateNode, "Line01", "Scenes.scnassets/chess/chess", 1);
        }
Beispiel #30
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);
        }