示例#1
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            SoundManager.PlaySound("miss");

            var imageAnchor = anchor as ARImageAnchor;
            var refSize     = imageAnchor.ReferenceImage.PhysicalSize;
            var box         = new SCNBox
            {
                Width         = refSize.Width * .9f,
                Length        = refSize.Height * .9f,
                Height        = 0.0001f,
                ChamferRadius = 0
            };

            box.FirstMaterial.Diffuse.Contents = UIColor.White.ColorWithAlpha(.95f);

            var pf = Prefabs[i++];

            node.AddChildNode(new SCNNode {
                Geometry = box
            });
            node.AddChildNode(pf);

            pf.Position = SCNVector3.Zero;
        }
示例#2
0
        private SCNNode PlaceCube(ARAnchor anchor)
        {
            AnchorVisual visual = this.anchorVisuals.Values.FirstOrDefault(a => a.localAnchor == anchor);

            if (visual is null)
            {
                return(null);
            }

            Debug.WriteLine($"renderer:nodeForAnchor with local anchor {anchor} at {anchor.Transform}");
            SCNBox box = new SCNBox {
                Width = 0.2f, Height = 0.2f, Length = 0.2f
            };

            if (visual.identifier != this.unsavedAnchorId)
            {
                box.FirstMaterial.Diffuse.Contents = this.foundColor;
            }
            else
            {
                box.FirstMaterial.Diffuse.Contents = this.readyColor;
            }

            this.localAnchorCube = box;
            SCNNode cubeNode = new SCNNode
            {
                Position = visual.localAnchor.Transform.ToPosition(),
                Geometry = box
            };

            this.sceneView.Scene.RootNode.AddChildNode(cubeNode);
            visual.node = cubeNode;

            return(visual.node);
        }
示例#3
0
            public void Set(float x, float y, float width, float height, float radius, ref Style style)
            {
                if (this.x != x || this.y != y || this.width != width || this.height != height || this.radius != radius)
                {
                    //Console.WriteLine ($"({this.sx} == {sx} && {this.sy} == {sy} && {this.ex} == {ex} && {this.ey == ey})");
                    this.x      = x;
                    this.y      = y;
                    this.width  = width;
                    this.height = height;
                    this.radius = radius;

                    //Console.WriteLine (style.Transform);

                    var g = SCNBox.Create(this.width, this.height, radius * 2, radius);
                    g.FirstMaterial = GetNativeMaterial(style.Color);
                    Geometry        = g;

                    base.Transform =
                        SCNMatrix4.CreateTranslation(this.x + this.width / 2, this.y + this.height / 2, 0)
                        * style.Transform
                    ;
                }
                if (ColorChanged(ref style))
                {
                    this.style.Color = style.Color;
                    if (Geometry is SCNGeometry g)
                    {
                        g.FirstMaterial = GetNativeMaterial(style.Color);
                    }
                }
            }
示例#4
0
        private void drawItem()
        {
            bool RColor = true;

            foreach (var i in items)
            {
                var w = (nfloat)i.PackDimX;
                var h = (nfloat)i.PackDimY;
                var d = (nfloat)i.PackDimZ;

                var item     = SCNBox.Create(w, h, d, 0);
                var itemNode = SCNNode.FromGeometry(item);
                if (RColor)
                {
                    item.FirstMaterial.Diffuse.Contents = randomColor(RColor);
                    RColor = false;
                }
                else
                {
                    item.FirstMaterial.Diffuse.Contents = randomColor(RColor);
                    RColor = true;
                }
                itemNode.Position = calculateRelativePosition(i);

                itemsNodeMap.Add(i, itemNode);
                scene.RootNode.AddChildNode(itemNode);
            }
        }
示例#5
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 SCNNode GetBox()
        {
            if (_prefab != null)
            {
                return(_prefab.Clone());
            }

            var g = new SCNBox {
                Height = .066f, Width = .066f, Length = .066f
            };

            g.FirstMaterial.Diffuse.Contents = UIImage.FromFile("xamagon-fill");

            var box = new SCNNode {
                Geometry = g
            };

            box.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Dynamic, SCNPhysicsShape.Create(g, new SCNPhysicsShapeOptions {
                ShapeType = SCNPhysicsShapeType.BoundingBox
            }));
            box.PhysicsBody.ContinuousCollisionDetectionThreshold = g.Width * 2;

            _prefab = box;

            return(_prefab.Clone());
        }
示例#7
0
        void Initialize()
        {
            BackgroundColor = NSColor.Black;
            var root = scene.RootNode;

            root.AddChildNode(camNode);
            root.AddChildNode(viewsNode);

            var backgroundGeom = SCNBox.Create(10000, 10000, 10, 0);

            backgroundGeom.FirstMaterial = Materials.Plastic(Xyzw(0.8, 1, 0.8, 1), roughness: 0.1).SCNMaterial;
            var backgroundNode = SCNNode.FromGeometry(backgroundGeom);

            backgroundNode.Position = Xyz(0, 0, -5.01).ToSCNVector3();
            viewsNode.AddChildNode(backgroundNode);

            AllowsCameraControl = true;

            scene.Background.ContentImage = new NSImage(
                NSBundle.MainBundle.PathForResource("environment", "jpg"));
            scene.Background.ContentsTransform = SCNMatrix4.CreateRotationX((float)(Math.PI / 2));

            scene.LightingEnvironment.ContentImage      = scene.Background.ContentImage;
            scene.LightingEnvironment.ContentsTransform = SCNMatrix4.CreateRotationX((float)(Math.PI / 2));

            Scene = scene;

            UpdateCamera();
        }
示例#8
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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            //let's create a geometric object
            var box = SCNBox.Create(0.1f, 0.1f, 0.1f, 0);

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

            //let's add the box to a SCNNode
            var newNode = new SCNNode();

            newNode.Geometry = box;
            newNode.Position = new SCNVector3(0, 0, -1);

            //Let's create a scene where this node will live in
            var scene = new SCNScene();

            scene.RootNode.Add(newNode);

            //set the scene in the sceneview to display it.
            SceneView.Scene = scene;

            SceneView.DebugOptions = ARKit.ARSCNDebugOptions.ShowFeaturePoints | ARKit.ARSCNDebugOptions.ShowWorldOrigin;


            SceneView.Session.Run(new ARKit.ARWorldTrackingConfiguration()
            {
                PlaneDetection         = ARKit.ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true,
                AutoFocusEnabled       = true,
                WorldAlignment         = ARKit.ARWorldAlignment.Gravity
            }, ARKit.ARSessionRunOptions.ResetTracking);
        }
示例#10
0
        public override void OnNodeAddedForAnchor(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            base.OnNodeAddedForAnchor(renderer, node, anchor);

            SoundManager.PlaySound("miss");

            var imageAnchor = anchor as ARImageAnchor;
            var refSize     = imageAnchor.ReferenceImage.PhysicalSize;
            var box         = new SCNBox
            {
                Width         = refSize.Width * 1.75f,
                Length        = refSize.Height * 1.75f,
                Height        = 0.0001f,
                ChamferRadius = 0
            };

            box.FirstMaterial.Diffuse.Contents = ShaderScene.Random();
            box.TileTexture(3);

            var pf = Prefabs[i++];

            node.AddChildNode(new SCNNode {
                Geometry = box
            });
            node.AddChildNode(pf);

            pf.Position = SCNVector3.Zero;
            pf.RunAction(SCNAction.RotateBy(0, 1.5f, 0, 0.01));
        }
示例#11
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);
            }
        }
示例#12
0
 public void CreateUser()
 {
     userShape        = SCNBox.Create(8.0f, 7.0f, 15.0f, 0.005f);
     user             = SCNNode.FromGeometry(userShape); // Creating a new node, user, that inherits the shape of the SCNBox, userShape
     user.Position    = new SCNVector3(10, 4, -50);
     user.PhysicsBody = SCNPhysicsBody.                  // Trying to set a physics body for the user in order for us to give controls to it
                        gameScene.RootNode.AddChildNode(user);
 }
示例#13
0
        private SCNGeometry CreateBlockMesh(SCNVector3 size)
        {
            var diceMesh = SCNBox.Create(size.X, size.Y, size.Z, 0.05f * size.X);

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

            return(diceMesh);
        }
示例#14
0
        private static SCNGeometry CreateGeometry(float size, UIColor color)
        {
            var geometry = SCNBox.Create(size, size, size, 0);
            var material = new SCNMaterial();

            material.Diffuse.Contents = color;

            geometry.Materials = new[] { material };

            return(geometry);
        }
示例#15
0
            public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
            {
                if (anchor is ARImageAnchor imageAnchor)
                {
                    var box = new SCNBox();

                    nfloat width  = imageAnchor.ReferenceImage.PhysicalSize.Width;
                    nfloat height = imageAnchor.ReferenceImage.PhysicalSize.Height;

                    box.Width  = width;
                    box.Height = height;
                    box.Length = (System.nfloat) 0.1;
                    box.FirstMaterial.Diffuse.Contents = UIColor.Orange;

                    SCNText text = SCNText.Create("Enter Here", (System.nfloat) 0.1);
                    text.Font     = UIFont.SystemFontOfSize(1);
                    text.Flatness = (System.nfloat) 0.05;
                    text.FirstMaterial.Diffuse.Contents = UIColor.Red;


                    var textNode = new SCNNode
                    {
                        Geometry = text,
                    };



                    textNode.Scale       = new SCNVector3((float)0.5, (float)0.5, (float)0.5);
                    textNode.EulerAngles = new SCNVector3((float)(-1.57), 0, 0);

                    textNode.Position = new SCNVector3
                    {
                        X = (float)(imageAnchor.Transform.Column3.X + 2),
                        Y = imageAnchor.Transform.Column3.Y - 2,
                        Z = imageAnchor.Transform.Column3.Z
                    };



                    var boxNode = new SCNNode
                    {
                        Geometry = box,

                        Position = new SCNVector3 {
                            X = -imageAnchor.Transform.Column3.X / 2,
                            Y = -imageAnchor.Transform.Column3.Y,
                            Z = imageAnchor.Transform.Column3.Z
                        }
                    };

                    node.AddChildNode(textNode);
                    //node.AddChildNode(boxNode);
                }
            }
示例#16
0
        //TODO 2.1 Añadiendo elementos
        private void AddBox()
        {
            SCNNode boxNode = new SCNNode();

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

            sceneView.Scene.RootNode.AddChildNode(boxNode);
        }
示例#17
0
        SCNNode PlaceCube()
        {
            var box = new SCNBox {
                Width = 0.25f, Height = 0.25f, Length = 0.25f
            };
            var cubeNode = new SCNNode {
                Geometry = box
            };

            cubeNode.Geometry.Materials = LoadMaterials();
            return(cubeNode);
        }
示例#18
0
            SCNNode MakeBox(ARAnchor anchor)
            {
                Console.WriteLine($"MakeBox ({anchor})");

                var geometry = SCNBox.Create(0.1f, 0.1f, 0.1f, 0);

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

                var gnode = SCNNode.FromGeometry(geometry);

                return(gnode);
            }
示例#19
0
        private static SCNBox CreateGeometry(ARPlaneAnchor planeAnchor)
        {
            var geometry       = SCNBox.Create(planeAnchor.Extent.X, PlaneHeight, planeAnchor.Extent.Z, 0);
            var topMaterial    = new SCNMaterial();
            var bottomMaterial = new SCNMaterial();

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

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

            return(geometry);
        }
示例#20
0
        SCNNode PlaceCube(SCNVector3 pos)
        {
            var box = new SCNBox {
                Width = 0.25f, Height = 0.25f, Length = 0.25f
            };
            var cubeNode = new SCNNode {
                Position = pos, Geometry = box
            };

            cubeNode.Geometry.Materials = LoadMaterials();
            scnView.Scene.RootNode.AddChildNode(cubeNode);
            return(cubeNode);
        }
        public SCNNode SpawnBox(ARRaycastResult raycast)
        {
            var geom = new SCNBox {
                Width = .15f, Height = .15f, Length = .15f
            };

            geom.FirstMaterial.Diffuse.Contents = UIColor.Black.ColorWithAlpha(.75f);
            geom.FirstMaterial.DoubleSided      = true;

            var box = new SCNNode {
                Geometry = geom, Transform = raycast.WorldTransform.ToSCNMatrix4()
            };

            SCNView.Scene.RootNode.Add(box);

            return(box);
        }
示例#22
0
        public CubeNode(float size, UIColor color)
        {
            SCNMaterial material = new SCNMaterial();

            material.Diffuse.Contents = color;

            SCNBox geometry = SCNBox.Create(size, size, size, 0);

            geometry.Materials = new[] { material };

            SCNNode node = new SCNNode
            {
                Geometry = geometry
            };

            AddChildNode(node);
        }
示例#23
0
        private void AddRelativeNodes()
        {
            SCNNode boxNode = new SCNNode();

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

            SCNNode sphereNode = new SCNNode();

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

            sceneView.Scene.RootNode.AddChildNode(boxNode); //Se coloca boxNode en una posición absoluta respecto a rootNode
            boxNode.AddChildNode(sphereNode);               //Se coloca sphereNode en una posición relativa a boxNode
        }
示例#24
0
        private void PresentHinge(PresentationViewController presentationViewController)
        {
            var count = 10.0f;

            var material = SCNMaterial.Create();

            material.Diffuse.Contents        = NSColor.White;
            material.Specular.Contents       = NSColor.White;
            material.LocksAmbientWithDiffuse = true;

            var cubeWidth  = 10.0f / count;
            var cubeHeight = 0.2f;
            var cubeLength = 5.0f;
            var offset     = 0;
            var height     = 5 + count * cubeWidth;

            SCNNode oldModel = null;

            for (int i = 0; i < count; ++i)
            {
                var model = SCNNode.Create();

                var worldtr = GroundNode.ConvertTransformToNode(SCNMatrix4.CreateTranslation(-offset + cubeWidth * i, height, 5), null);

                model.Transform = worldtr;

                model.Geometry = SCNBox.Create(cubeWidth, cubeHeight, cubeLength, 0);
                model.Geometry.FirstMaterial = material;

                var body = SCNPhysicsBody.CreateDynamicBody();
                body.Restitution  = 0.6f;
                model.PhysicsBody = body;

                ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(model);

                var joint = SCNPhysicsHingeJoint.Create(model.PhysicsBody, new SCNVector3(0, 0, 1), new SCNVector3(-cubeWidth * 0.5f, 0, 0), (oldModel != null ? oldModel.PhysicsBody : null), new SCNVector3(0, 0, 1), new SCNVector3(cubeWidth * 0.5f, 0, 0));
                ((SCNView)presentationViewController.View).Scene.PhysicsWorld.AddBehavior(joint);

                Hinges.Add(model);

                oldModel = model;
            }
        }
        public SCNNode SpawnBox()
        {
            var pos = SCNView.PointOfView.ConvertPositionToNode(new SCNVector3(0.01f, -.1f, -.4f), SCNView.Scene.RootNode);

            var geom = new SCNBox {
                Width = .15f, Height = .15f, Length = .15f
            };

            geom.FirstMaterial.Diffuse.Contents = UIColor.Black.ColorWithAlpha(.75f);
            geom.FirstMaterial.DoubleSided      = true;

            var box = new SCNNode
            {
                Geometry = geom,
                Position = pos
            };

            SCNView.Scene.Add(box);

            return(box);
        }
示例#26
0
        SCNNode CreateTorchNode()
        {
            SCNGeometry geometry = SCNBox.Create(20f, 100f, 20f, 0f);

            geometry.FirstMaterial.Diffuse.Contents = AppKit.NSColor.Brown;
            var template = new SCNNode {
                Geometry = geometry
            };

            var particleEmitter = new SCNNode {
                Position = new SCNVector3(0f, 50f, 0f)
            };

            SCNParticleSystem fire = GameSimulation.LoadParticleSystemWithName("torch", "spark");

            particleEmitter.AddParticleSystem(fire);
            particleEmitter.Light = TorchLight;

            template.AddChildNode(particleEmitter);
            return(template);
        }
示例#27
0
        private void drawBox()
        {
            var border = 0.05f;
            //var w = (nfloat)(Math.Round(Box.Width, 0, MidpointRounding.AwayFromZero) + border);
            //var h = (nfloat)(Math.Round(Box.Height, 0, MidpointRounding.AwayFromZero) + border);
            //var d = (nfloat)(Math.Round(Box.Depth, 0, MidpointRounding.AwayFromZero) + border);

            var w = (nfloat)Box.Width + border;
            var h = (nfloat)Box.Height + border;
            var d = (nfloat)Box.Depth + border;

            var boxGeometry = SCNBox.Create(d, h, w, 0);

            boxNode = SCNNode.FromGeometry(boxGeometry);

            boxGeometry.FirstMaterial.Diffuse.Contents = UIColor.Black;
            boxGeometry.FirstMaterial.FillMode         = SCNFillMode.Lines;
            boxGeometry.FirstMaterial.DoubleSided      = true;
            boxNode.Position = new SCNVector3(0, 0, 0);

            scene.RootNode.AddChildNode(boxNode);
        }
示例#28
0
        public static SCNNode CreateAxesNode(float quiverLength, float quiverThickness)
        {
            quiverThickness = (quiverLength / 50f) * quiverThickness;
            var chamferRadius = quiverThickness / 2f;

            var xQuiverBox = SCNBox.Create(quiverLength, quiverThickness, quiverThickness, chamferRadius);

            xQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Red, false), 0);
            var xQuiverNode = SCNNode.FromGeometry(xQuiverBox);

            xQuiverNode.Position = new SCNVector3((quiverLength / 2f), 0, 0);

            var yQuiverBox = SCNBox.Create(quiverThickness, quiverLength, quiverThickness, chamferRadius);

            yQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Green, false), 0);
            var yQuiverNode = SCNNode.FromGeometry(yQuiverBox);

            yQuiverNode.Position = new SCNVector3(0, (quiverLength / 2f), 0);

            var zQuiverBox = SCNBox.Create(quiverThickness, quiverThickness, quiverLength, chamferRadius);

            zQuiverBox.InsertMaterial(SCNMaterialExtensions.CreateMaterial(UIColor.Blue, false), 0);
            var zQuiverNode = SCNNode.FromGeometry(zQuiverBox);

            zQuiverNode.Position = new SCNVector3(0, 0, (quiverLength / 2f));

            // Assemble node
            var quiverNode = new SCNNode()
            {
                Name = "Axes"
            };

            quiverNode.AddChildNode(xQuiverNode);
            quiverNode.AddChildNode(yQuiverNode);
            quiverNode.AddChildNode(zQuiverNode);

            // Return results
            return(quiverNode);
        }
示例#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);
        }
示例#30
0
        private void VisualizeBones(bool show, SCNNode node, nfloat scale)
        {
            // We propagate an inherited scale so that the boxes
            // representing the bones will be of the same size
            scale *= node.Scale.X;

            if (show)
            {
                if (node.Geometry == null)
                {
                    node.Geometry = SCNBox.Create(6.0f / scale, 6.0f / scale, 6.0f / scale, 0.5f);
                }
            }
            else
            {
                if (node.Geometry.GetType() == typeof(SCNBox))
                {
                    node.Geometry = null;
                }
            }

            //foreach (SCNNode child in node.ChildNodes)
            //VisualizeBones (show, child, scale);
        }
		private void SetupSceneElements (SCNScene scene)
		{
			AddTrainToScene (scene, new SCNVector3 (-5f, 20f, -40f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"), new SCNVector3 (-10f, 15f, 10f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeB.jpg"), new SCNVector3 (-9f, 10f, 10f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeC.jpg"), new SCNVector3 (20f, 15f, -11f));
			AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"), new SCNVector3 (25f, 5f, -20f));

			var wallBox = new SCNBox {
				Width = 400f,
				Height = 100f,
				Length = 4f,
				ChamferRadius = 0f
			};

			var wall = SCNNode.FromGeometry (wallBox);
			wall.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("wall.jpg");
			wall.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Mult (
				SCNMatrix4.Scale (24f, 2f, 1f),
				SCNMatrix4.CreateTranslation (0f, 1f, 0f)
			);

			wall.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Repeat;
			wall.Geometry.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Mirror;
			wall.Geometry.FirstMaterial.DoubleSided = false;
			wall.CastsShadow = false;
			wall.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;

			wall.Position = new SCNVector3 (0f, 50f, -92f);
			wall.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			scene.RootNode.AddChildNode (wall);

			wall = wall.Clone ();
			wall.Position = new SCNVector3 (202f, 50f, 0f);
			wall.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI / 2f);
			scene.RootNode.AddChildNode (wall);

			wall = wall.Clone ();
			wall.Position = new SCNVector3 (-202f, 50f, 0f);
			wall.Rotation = new SCNVector4 (0f, 1f, 0f, -(float)Math.PI / 2f);
			scene.RootNode.AddChildNode (wall);

			var planeGeometry = new SCNPlane {
				Width = 400f,
				Height = 100f
			};

			var backWall = SCNNode.FromGeometry (planeGeometry);
			backWall.Geometry.FirstMaterial = wall.Geometry.FirstMaterial;
			backWall.Position = new SCNVector3 (0f, 50f, 200f);
			backWall.Rotation = new SCNVector4 (0f, 1f, 0f, (float)Math.PI);
			backWall.CastsShadow = false;
			backWall.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			scene.RootNode.AddChildNode (backWall);

			planeGeometry = new SCNPlane {
				Width = 400f,
				Height = 400f
			};

			var ceilNode = SCNNode.FromGeometry (planeGeometry);
			ceilNode.Position = new SCNVector3 (0f, 100f, 0f);
			ceilNode.Rotation = new SCNVector4 (1f, 0f, 0f, (float)Math.PI / 2f);
			ceilNode.Geometry.FirstMaterial.DoubleSided = false;
			ceilNode.CastsShadow = false;
			ceilNode.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			scene.RootNode.AddChildNode (ceilNode);

			var rnd = new Random ();
			for (int i = 0; i < 4; i++) {
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeA.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeB.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
				AddWoodenBlockToScene (scene, ResourceManager.GetResourcePath ("WoodCubeC.jpg"),
					new SCNVector3 (rnd.Next (0, 60) - 30f, 20f, rnd.Next (0, 40) - 20f));
			}

			var blockBox = new SCNBox {
				Width = 22f,
				Height = 0.2f,
				Length = 34f,
				ChamferRadius = 0f
			};

			var block = SCNNode.Create ();
			block.Position = new SCNVector3 (20f, 10f, -16f);
			block.Rotation = new SCNVector4 (0f, 1f, 0f, (float)-Math.PI / 4f);
			block.Geometry = blockBox;

			var frontMat = SCNMaterial.Create ();
			frontMat.LocksAmbientWithDiffuse = true;
			frontMat.Diffuse.Contents = ResourceManager.GetResourcePath ("book_front.jpg");
			frontMat.Diffuse.MipFilter = SCNFilterMode.Linear;

			var backMat = SCNMaterial.Create ();
			backMat.LocksAmbientWithDiffuse = true;
			backMat.Diffuse.Contents = ResourceManager.GetResourcePath ("book_back.jpg");
			backMat.Diffuse.MipFilter = SCNFilterMode.Linear;

			block.Geometry.Materials = new SCNMaterial[] { frontMat, backMat };
			block.PhysicsBody = SCNPhysicsBody.CreateDynamicBody ();
			scene.RootNode.AddChildNode (block);

			var rug = SCNNode.Create ();
			rug.Position = new SCNVector3 (0f, 0.01f, 0f);
			rug.Rotation = new SCNVector4 (1f, 0f, 0f, (float)Math.PI / 2f);
			var path = UIBezierPath.FromRoundedRect (new CGRect (-50f, -30f, 100f, 50f), 2.5f);
			path.Flatness = 0.1f;
			rug.Geometry = SCNShape.Create (path, 0.05f);
			rug.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			rug.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("carpet.jpg");
			scene.RootNode.AddChildNode (rug);

			var ball = SCNNode.Create ();
			ball.Position = new SCNVector3 (-5f, 5f, -18f);
			ball.Geometry = SCNSphere.Create (5f);
			ball.Geometry.FirstMaterial.LocksAmbientWithDiffuse = true;
			ball.Geometry.FirstMaterial.Diffuse.Contents = ResourceManager.GetResourcePath ("ball.jpg");
			ball.Geometry.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.Scale (2f, 1f, 1f);
			ball.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Mirror;
			ball.PhysicsBody = SCNPhysicsBody.CreateDynamicBody ();
			ball.PhysicsBody.Restitution = 0.9f;
			scene.RootNode.AddChildNode (ball);
		}
		private void AddTrainToScene (SCNScene scene, SCNVector3 position)
		{
			var max = SCNVector3.Zero;
			var min = SCNVector3.Zero;
			var trainScene = SCNScene.FromFile ("train_flat", ResourceManager.ResourceFolder, (NSDictionary)null);

			foreach (var node in trainScene.RootNode.ChildNodes) {
				if (node.Geometry != null) {
					node.Position = new SCNVector3 (
						node.Position.X + position.X,
						node.Position.Y + position.Y,
						node.Position.Z + position.Z
					);

					max = SCNVector3.Zero;
					min = SCNVector3.Zero;

					node.GetBoundingBox (ref min, ref max);

					var body = SCNPhysicsBody.CreateDynamicBody ();
					var boxShape = new SCNBox {
						Width = max.X - min.X,
						Height = max.Y - min.Y,
						Length = max.Z - min.Z,
						ChamferRadius = 0f
					};

					body.PhysicsShape = SCNPhysicsShape.Create (boxShape, (NSDictionary)null);
					node.Pivot = SCNMatrix4.CreateTranslation (0f, -min.Y, 0f);
					node.PhysicsBody = body;
					scene.RootNode.AddChildNode (node);
				}
			}

			var smokeHandle = scene.RootNode.FindChildNode ("Smoke", true);
			var smokeParticleSystem = SCNParticleSystem.Create ("smoke", ResourceManager.ResourceFolder);
			smokeParticleSystem.ParticleImage = ResourceManager.GetResourcePath ("smoke.png");
			smokeHandle.AddParticleSystem (smokeParticleSystem);

			var engineCar = scene.RootNode.FindChildNode ("EngineCar", false);
			var wagon1 = scene.RootNode.FindChildNode ("Wagon1", false);
			var wagon2 = scene.RootNode.FindChildNode ("Wagon2", false);

			max = SCNVector3.Zero;
			min = SCNVector3.Zero;
			engineCar.GetBoundingBox (ref min, ref max);

			var wmax = SCNVector3.Zero;
			var wmin = SCNVector3.Zero;
			wagon1.GetBoundingBox (ref wmin, ref wmax);

			var anchorA = new SCNVector3 (max.X, min.Y, 0f);
			var anchorB = new SCNVector3 (wmin.X, wmin.Y, 0f);

			var joint = SCNPhysicsBallSocketJoint.Create (engineCar.PhysicsBody, anchorA, wagon1.PhysicsBody, anchorB);

			scene.PhysicsWorld.AddBehavior (joint);

			joint = SCNPhysicsBallSocketJoint.Create (wagon1.PhysicsBody,
				new SCNVector3 (wmax.X + 0.1f, wmin.Y, 0f),
				wagon2.PhysicsBody,
				new SCNVector3 (wmin.X - 0.1f, wmin.Y, 0f)
			);

			scene.PhysicsWorld.AddBehavior (joint);
		}