SCArrowBezierPath() public static method

public static SCArrowBezierPath ( CGSize baseSize, CGSize tipSize, nfloat hollow, bool twoSides ) : NSBezierPath
baseSize CGSize
tipSize CGSize
hollow nfloat
twoSides bool
return NSBezierPath
コード例 #1
0
ファイル: SlideSceneGraph.cs プロジェクト: spica/mac-samples
        public static SCNNode SharedScenegraphDiagramNode()
        {
            if (DiagramNode == null)
            {
                DiagramNode         = SCNNode.Create();
                DiagramNode.Opacity = 0.0f;


                // "Scene"
                var blue = NSColor.FromDeviceRgba(49.0f / 255.0f, 80.0f / 255.0f, 201.0f / 255.0f, 1);
                var box  = Utils.SCBoxNode("Scene", new CGRect(-53.5f, -25, 107, 50), blue, 10, true);
                box.Name     = "scene";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.4f, 4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow from "Scene" to "Root Node"
                var arrowNode = new SCNNode {
                    Name     = "sceneArrow",
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(3, 0.2f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Scale    = new SCNVector3(20, 20, 1),
                    Position = new SCNVector3(-5, 0, 8),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = blue;
                box.AddChildNode(arrowNode);


                // "Root Node"
                var green = NSColor.FromDeviceRgba(154.0f / 255.0f, 197.0f / 255.0f, 58.0f / 255.0f, 1);
                box          = Utils.SCBoxNode("Root Node", new CGRect(-40, -36, 80, 72), green, 10, true);
                box.Name     = "rootNode";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.405f, 1.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrows from "Root Node" to child nodes
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow1";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(5.8f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, true), 0);
                arrowNode.Position = new SCNVector3(0, -30, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.85f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow2";
                arrowNode.Position = new SCNVector3(0, -43, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * (1 - 0.85f)));
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "nodeArrow3";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.6f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, true), 0);
                arrowNode.Position = new SCNVector3(-4, -38, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.5f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = green;
                box.AddChildNode(arrowNode);


                // Multiple "Child Node"
                box          = Utils.SCBoxNode("Child Node", new CGRect(-40, -36, 80, 72), green, 10, true);
                box.Name     = "child1";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(2.405f, -2, 0);
                DiagramNode.AddChildNode(box);

                box          = box.Clone();
                box.Name     = "child2";
                box.Position = new SCNVector3(5.405f, -2, 0);
                DiagramNode.AddChildNode(box);

                box          = box.Clone();
                box.Name     = "child3";
                box.Position = new SCNVector3(8.405f, -2, 0);
                DiagramNode.AddChildNode(box);


                // "Light"
                var purple = NSColor.FromDeviceRgba(190.0f / 255.0f, 56.0f / 255.0f, 243.0f / 255.0f, 1);
                box          = Utils.SCBoxNode("Light", new CGRect(-40, -20, 80, 40), purple, 10, true);
                box.Name     = "light";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(2.405f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow to "Light"
                arrowNode = new SCNNode {
                    Name     = "lightArrow",
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Position = new SCNVector3(-5, 60, 8),
                    Scale    = new SCNVector3(20, 20, 1),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
                box.AddChildNode(arrowNode);


                // "Camera"
                box          = Utils.SCBoxNode("Camera", new CGRect(-45, -20, 90, 40), purple, 10, true);
                box.Name     = "camera";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(5.25f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrow to "Camera"
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "cameraArrow";
                arrowNode.Position = new SCNVector3(0, 60, 8);
                box.AddChildNode(arrowNode);


                // "Geometry"
                box          = Utils.SCBoxNode("Geometry", new CGRect(-55, -20, 110, 40), purple, 10, true);
                box.Name     = "geometry";
                box.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                box.Position = new SCNVector3(8.6f, -4.8f, 0);
                DiagramNode.AddChildNode(box);


                // Arrows to "Geometry"
                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "geometryArrow";
                arrowNode.Position = new SCNVector3(-10, 60, 8);
                box.AddChildNode(arrowNode);

                arrowNode          = arrowNode.Clone();
                arrowNode.Name     = "geometryArrow2";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(5.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0);
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = purple;
                arrowNode.Position = new SCNVector3(-105, 53, 8);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 8));
                box.AddChildNode(arrowNode);


                // Multiple "Material"
                var redColor = NSColor.FromDeviceRgba(168.0f / 255.0f, 21.0f / 255.0f, 0.0f / 255.0f, 1);

                var materialsBox = Utils.SCBoxNode(null, new CGRect(-151, -25, 302, 50), NSColor.LightGray, 2, true);
                materialsBox.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
                materialsBox.Name     = "materials";
                materialsBox.Position = new SCNVector3(8.7f, -7.1f, -0.2f);
                DiagramNode.AddChildNode(materialsBox);

                box          = Utils.SCBoxNode("Material", new CGRect(-45, -20, 90, 40), redColor, 0, true);
                box.Position = new SCNVector3(-100, 0, 0.2f);
                materialsBox.AddChildNode(box);

                box          = box.Clone();
                box.Position = new SCNVector3(100, 0, 0.2f);
                materialsBox.AddChildNode(box);

                box          = box.Clone();
                box.Position = new SCNVector3(0, 0, 0.2f);
                materialsBox.AddChildNode(box);

                // Arrow from "Geometry" to the materials
                arrowNode = new SCNNode {
                    Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.0f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0),
                    Position = new SCNVector3(-6, 65, 8),
                    Scale    = new SCNVector3(20, 20, 1),
                    Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2))
                };
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = redColor;
                box.AddChildNode(arrowNode);

                materialsBox.ParentNode.ReplaceChildNode(materialsBox, materialsBox.FlattenedClone());
            }
            return(DiagramNode);
        }
コード例 #2
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                // Set the slide's title and subtitle and add some text
                TextManager.SetTitle("Performance");
                TextManager.SetSubtitle("Copying");

                TextManager.AddBulletAtLevel("Attributes are shared by default", 0);
                TextManager.AddBulletAtLevel("Unshare if needed", 0);
                TextManager.AddBulletAtLevel("Copying geometries is cheap", 0);

                break;

            case 1:
                // New "Node B" box
                var nodeB = Utils.SCBoxNode("Node B", new CGRect(-55, -36, 110, 50), GreenColor, 10, true);
                nodeB.Name     = "nodeB";
                nodeB.Position = new SCNVector3(140, 0, 0);
                nodeB.Opacity  = 0;

                var nodeA = ContentNode.FindChildNode("nodeA", true);
                nodeA.AddChildNode(nodeB);

                // Arrow from "Root Node" to "Node B"
                var arrowNode = SCNNode.Create();
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(140, 3), new CGSize(10, 14), 4, true), 0);
                arrowNode.Position = new SCNVector3(-130, 60, 0);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.12f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = GreenColor;
                nodeB.AddChildNode(arrowNode);

                // Arrow from "Node B" to the shared geometry
                arrowNode          = SCNNode.Create();
                arrowNode.Name     = "arrow-shared-geometry";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(140, 3), new CGSize(10, 14), 4, false), 0);
                arrowNode.Position = new SCNVector3(0, -28, 0);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI * 1.12f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = PurpleColor;
                nodeB.AddChildNode(arrowNode);

                // Reveal
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                nodeB.Opacity = 1.0f;

                // Show the related code
                TextManager.AddCode("#// Copy a node \n"
                                    + "var nodeB = nodeA.#Copy# ();#");
                SCNTransaction.Commit();
                break;

            case 2:
                var geometryNodeA = ContentNode.FindChildNode("geometry", true);
                var oldArrowNode  = ContentNode.FindChildNode("arrow-shared-geometry", true);

                // New "Geometry" box
                var geometryNodeB = Utils.SCBoxNode("Geometry", new CGRect(-55, -20, 110, 40), PurpleColor, 10, true);
                geometryNodeB.Position = new SCNVector3(140, 0, 0);
                geometryNodeB.Opacity  = 0;
                geometryNodeA.AddChildNode(geometryNodeB);

                // Arrow from "Node B" to the new geometry
                arrowNode          = SCNNode.Create();
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(55, 3), new CGSize(10, 14), 4, false), 0);
                arrowNode.Position = new SCNVector3(0, 75, 0);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.5f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = PurpleColor;
                geometryNodeB.AddChildNode(arrowNode);

                // Arrow from the new geometry to "Material"
                arrowNode          = SCNNode.Create();
                arrowNode.Name     = "arrow-shared-material";
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(140, 3), new CGSize(10, 14), 4, true), 0);
                arrowNode.Position = new SCNVector3(-130, -80, 0);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI * 0.12f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = RedColor;
                geometryNodeB.AddChildNode(arrowNode);

                // Reveal
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                geometryNodeB.Opacity            = 1.0f;
                oldArrowNode.Opacity             = 0.0f;

                // Show the related code
                TextManager.AddEmptyLine();
                TextManager.AddCode("#// Unshare geometry \n"
                                    + "nodeB.Geometry = nodeB.Geometry.#Copy# ();#");
                SCNTransaction.Commit();
                break;

            case 3:
                var materialANode = ContentNode.FindChildNode("material", true);
                oldArrowNode = ContentNode.FindChildNode("arrow-shared-material", true);

                // New "Material" box
                var materialBNode = Utils.SCBoxNode("Material", new CGRect(-55, -20, 110, 40), NSColor.Orange, 10, true);
                materialBNode.Position = new SCNVector3(140, 0, 0);
                materialBNode.Opacity  = 0;
                materialANode.AddChildNode(materialBNode);

                // Arrow from the unshared geometry to the new material
                arrowNode          = SCNNode.Create();
                arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(55, 3), new CGSize(10, 14), 4, false), 0);
                arrowNode.Position = new SCNVector3(0, 75, 0);
                arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.5f));
                arrowNode.Geometry.FirstMaterial.Diffuse.Contents = NSColor.Orange;
                materialBNode.AddChildNode(arrowNode);

                // Reveal
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                materialBNode.Opacity            = 1.0f;
                oldArrowNode.Opacity             = 0.0f;
                SCNTransaction.Commit();
                break;
            }
        }
コード例 #3
0
        private void SetupLookAtScene()
        {
            var intermediateNode = SCNNode.Create();

            intermediateNode.Scale    = new SCNVector3(0.5f, 0.5f, 0.5f);
            intermediateNode.Position = new SCNVector3(0, 0, 10);
            ContentNode.AddChildNode(intermediateNode);

            var ballMaterial = SCNMaterial.Create();

            ballMaterial.Diffuse.Contents     = new NSImage(NSBundle.MainBundle.PathForResource("Scenes/pool/pool_8", "png"));
            ballMaterial.Specular.Contents    = NSColor.White;
            ballMaterial.Shininess            = 0.9f;  // shinny
            ballMaterial.Reflective.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/color_envmap", "png"));
            ballMaterial.Reflective.Intensity = 0.5f;

            // Node hierarchy for the ball :
            //   _ballNode
            //  |__ cameraTarget      : the target for the "look at" constraint
            //  |__ ballRotationNode  : will rotate to animate the rolling ball
            //      |__ ballPivotNode : will own the geometry and will be rotated so that the "8" faces the camera at the beginning

            BallNode          = SCNNode.Create();
            BallNode.Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 4));
            intermediateNode.AddChildNode(BallNode);

            var cameraTarget = SCNNode.Create();

            cameraTarget.Name     = "cameraTarget";
            cameraTarget.Position = new SCNVector3(0, 6, 0);
            BallNode.AddChildNode(cameraTarget);

            var ballRotationNode = SCNNode.Create();

            ballRotationNode.Position = new SCNVector3(0, 4, 0);
            BallNode.AddChildNode(ballRotationNode);

            var ballPivotNode = SCNNode.Create();

            ballPivotNode.Geometry = SCNSphere.Create(4.0f);
            ballPivotNode.Geometry.FirstMaterial = ballMaterial;
            ballPivotNode.Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 2));
            ballRotationNode.AddChildNode(ballPivotNode);

            var arrowMaterial = SCNMaterial.Create();

            arrowMaterial.Diffuse.Contents    = NSColor.White;
            arrowMaterial.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/chrome", "jpg"));

            var arrowContainer = SCNNode.Create();

            arrowContainer.Name = "arrowContainer";
            intermediateNode.AddChildNode(arrowContainer);

            var arrowPath = Utils.SCArrowBezierPath(new CGSize(6, 2), new CGSize(3, 5), 0.5f, false);

            // Create the arrows
            for (var i = 0; i < 11; i++)
            {
                var arrowNode = SCNNode.Create();
                arrowNode.Position = new SCNVector3((float)Math.Cos(Math.PI * i / 10.0f) * 20.0f, 3 + 18.5f * (float)Math.Sin(Math.PI * i / 10.0f), 0);

                var arrowGeometry = SCNShape.Create(arrowPath, 1);
                arrowGeometry.ChamferRadius = 0.2f;

                var arrowSubNode = SCNNode.Create();
                arrowSubNode.Geometry = arrowGeometry;
                arrowSubNode.Geometry.FirstMaterial = arrowMaterial;
                arrowSubNode.Pivot    = SCNMatrix4.CreateTranslation(new SCNVector3(0, 2.5f, 0));                // place the pivot (center of rotation) at the middle of the arrow
                arrowSubNode.Rotation = new SCNVector4(0, 0, 1, (float)(Math.PI / 2));

                arrowNode.AddChildNode(arrowSubNode);
                arrowContainer.AddChildNode(arrowNode);
            }
        }
コード例 #4
0
        // A node hierarchy that illustrates the cloning mechanism and how to unshare attributes
        private SCNNode CloningDiagramNode()
        {
            var diagramNode = SCNNode.Create();

            diagramNode.Position = new SCNVector3(7, 9, 3);

            // "Scene" box
            var sceneNode = Utils.SCBoxNode("Scene", new CGRect(-53.5f, -25, 107, 50), BlueColor, 10, true);

            sceneNode.Name     = "scene";
            sceneNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            sceneNode.Position = new SCNVector3(0, 4.8f, 0);
            diagramNode.AddChildNode(sceneNode);

            // "Root node" box
            var rootNode = Utils.SCBoxNode("Root Node", new CGRect(-40, -36, 80, 72), GreenColor, 10, true);

            rootNode.Name     = "rootNode";
            rootNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            rootNode.Position = new SCNVector3(0.05f, 1.8f, 0);
            diagramNode.AddChildNode(rootNode);

            // "Node A" box
            var nodeA = Utils.SCBoxNode("Node A", new CGRect(-55, -36, 110, 50), GreenColor, 10, true);

            nodeA.Name     = "nodeA";
            nodeA.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            nodeA.Position = new SCNVector3(0, -1.4f, 0);
            diagramNode.AddChildNode(nodeA);

            // "Geometry" box
            var geometryNode = Utils.SCBoxNode("Geometry", new CGRect(-55, -20, 110, 40), PurpleColor, 10, true);

            geometryNode.Name     = "geometry";
            geometryNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            geometryNode.Position = new SCNVector3(0, -4.7f, 0);
            diagramNode.AddChildNode(geometryNode);

            // "Material" box
            var materialNode = Utils.SCBoxNode("Material", new CGRect(-55, -20, 110, 40), RedColor, 10, true);

            materialNode.Name     = "material";
            materialNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            materialNode.Position = new SCNVector3(0, -7.5f, 0);
            diagramNode.AddChildNode(materialNode);

            // Arrow from "Scene" to "Root Node"
            var arrowNode = SCNNode.Create();

            arrowNode.Name     = "sceneArrow";
            arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(3, 0.2f), new CGSize(0.5f, 0.7f), 0.2f, false), 0);
            arrowNode.Scale    = new SCNVector3(20, 20, 1);
            arrowNode.Position = new SCNVector3(-5, 0, 8);
            arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2));
            arrowNode.Geometry.FirstMaterial.Diffuse.Contents = BlueColor;
            sceneNode.AddChildNode(arrowNode);

            // Arrow from "Root Node" to "Node A"
            arrowNode          = arrowNode.Clone();
            arrowNode.Name     = "arrow";
            arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.6f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, true), 0);
            arrowNode.Position = new SCNVector3(-6, -38, 8);
            arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI * 0.5f));
            arrowNode.Geometry.FirstMaterial.Diffuse.Contents = GreenColor;
            rootNode.AddChildNode(arrowNode);

            // Arrow from "Node A" to "Geometry"
            arrowNode          = arrowNode.Clone();
            arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.6f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0);
            arrowNode.Position = new SCNVector3(-5, 74, 8);
            arrowNode.Scale    = new SCNVector3(20, 20, 1);
            arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2));
            arrowNode.Geometry.FirstMaterial.Diffuse.Contents = PurpleColor;
            geometryNode.AddChildNode(arrowNode);

            // Arrow from "Geometry" to "Material"
            arrowNode          = arrowNode.Clone();
            arrowNode.Geometry = SCNShape.Create(Utils.SCArrowBezierPath(new CGSize(2.7f, 0.15f), new CGSize(0.5f, 0.7f), 0.2f, false), 0);
            arrowNode.Position = new SCNVector3(-6, 74, 8);
            arrowNode.Scale    = new SCNVector3(20, 20, 1);
            arrowNode.Rotation = new SCNVector4(0, 0, 1, -(float)(Math.PI / 2));
            arrowNode.Geometry.FirstMaterial.Diffuse.Contents = RedColor;
            materialNode.AddChildNode(arrowNode);

            return(diagramNode);
        }