public static SCBoxNode ( string title, CGRect frame, NSColor color, float cornerRadius, bool centered ) : SCNNode | ||
title | string | |
frame | CGRect | |
color | NSColor | |
cornerRadius | float | |
centered | bool | |
return | SCNNode |
public override void PresentStep(int index, PresentationViewController presentationViewController) { // Set the slide's title TextManager.SetTitle ("Labs"); // Add two labs var lab1TitleNode = Utils.SCBoxNode ("Scene Kit Lab", new CGRect (-375, -35, 750, 70), NSColor.FromCalibratedWhite (0.15f, 1.0f), 0.0f, false); lab1TitleNode.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f); lab1TitleNode.Position = new SCNVector3 (-2.8f, 30.7f, 10.0f); lab1TitleNode.Rotation = new SCNVector4 (1, 0, 0, (float)(Math.PI)); lab1TitleNode.Opacity = 0.0f; var lab2TitleNode = (SCNNode)lab1TitleNode.Copy (); lab2TitleNode.Position = new SCNVector3 (-2.8f, 29.2f, 10.0f); ContentNode.AddChildNode (lab1TitleNode); ContentNode.AddChildNode (lab2TitleNode); var lab1InfoNode = AddLabInfoNode ("\nGraphics and Games Lab A\nTuesday 4:00PM", 30.7f); var lab2InfoNode = AddLabInfoNode ("\nGraphics and Games Lab A\nWednesday 9:00AM", 29.2f); var delayInSeconds = 0.75; var popTime = new DispatchTime (DispatchTime.Now, (long)(delayInSeconds * Utils.NSEC_PER_SEC)); DispatchQueue.MainQueue.DispatchAfter (popTime, () => { SCNTransaction.Begin (); SCNTransaction.AnimationDuration = 1; lab1TitleNode.Opacity = lab2TitleNode.Opacity = 1.0f; lab1TitleNode.Rotation = lab2TitleNode.Rotation = new SCNVector4 (1, 0, 0, 0); lab1InfoNode.Opacity = lab2InfoNode.Opacity = 1.0f; lab1InfoNode.Rotation = lab2InfoNode.Rotation = new SCNVector4 (0, 1, 0, 0); SCNTransaction.Commit (); }); }
private void AddBox(string title, CGRect frame, int level, NSColor color) { var node = Utils.SCBoxNode(title, frame, color, 2.0f, true); node.Scale = new SCNVector3(0.02f, 0.02f, 0.02f); node.Position = new SCNVector3(-5, 1.5f * level, 10); ContentNode.AddChildNode(node); }
private SCNNode AddLabInfoNode(string title, float yPosition) { var labInfoNode = Utils.SCBoxNode (title, new CGRect (0, 0, 293.33f, 93.33f), NSColor.FromDeviceRgba (31 / 255, 31 / 255, 31 / 255, 1), 0.0f, false); labInfoNode.Scale = new SCNVector3 (0.015f, 0.015f, 0.015f); labInfoNode.Pivot = SCNMatrix4.CreateTranslation (new SCNVector3 (145.33f, 46.66f, 5)); labInfoNode.Position = new SCNVector3 (6.9f, yPosition, 10.0f); labInfoNode.Rotation = new SCNVector4 (0, 1, 0, (float)(Math.PI)); labInfoNode.Opacity = 0.0f; var colorBox = Utils.SCBoxNode (null, new CGRect (293.33f, 0, 40, 93.33f), NSColor.FromDeviceRgba (1, 214 / 255, 37 / 255, 1), 0.0f, false); colorBox.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant; ContentNode.AddChildNode (labInfoNode); labInfoNode.AddChildNode (colorBox); return labInfoNode; }
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); }
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; } }
// 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); }