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); }
public void Set(Polygon poly, ref Style style) { if (this.poly != poly) { //Console.WriteLine ($"({this.sx} == {sx} && {this.sy} == {sy} && {this.ex} == {ex} && {this.ey == ey})"); this.poly = poly; //Console.WriteLine (style.Transform); var ps = poly.Points; var n = ps.Count; if (n > 1) { var path = new NSBezierPath(); path.MoveTo(new CGPoint(ps[0].X, ps[0].Y)); for (var i = 1; i < n; i++) { path.LineTo(new CGPoint(ps[i].X, ps[i].Y)); } path.ClosePath(); var g = SCNShape.Create(path, 1); g.FirstMaterial = GetNativeMaterial(style.Color); Geometry = g; } else { Geometry = null; } Transform = style.Transform ; } if (ColorChanged(ref style)) { this.style.Color = style.Color; var g = Geometry; if (g is object) { g.FirstMaterial = GetNativeMaterial(style.Color); } } }
private SCNNode Level2() { var node = SCNNode.Create(); var roomsNode = SCNNode.Create(); var floor = SCNShape.Create(MosconeFloor(), 10.0f); var walls = SCNShape.Create(MosconeRooms(), 20.0f); node.Geometry = floor; node.Geometry.Materials = FloorMaterials(); roomsNode.Geometry = walls; roomsNode.Geometry.FirstMaterial = WallMaterial(); roomsNode.Pivot = SCNMatrix4.CreateTranslation(0, 0, -0.5f * 20.0f); roomsNode.Opacity = 1.0f; node.AddChildNode(roomsNode); return(node); }
private void AddPath() { SCNMaterial material = new SCNMaterial(); material.Specular.Contents = UIColor.White; //Color del reflejo material.Diffuse.Contents = UIColor.Blue; //Color del objeto var path = new UIBezierPath(); path.MoveTo(new CGPoint(0, 0)); path.AddLineTo(new CGPoint(0, 0.2)); path.AddLineTo(new CGPoint(0.2, 0.3)); path.AddLineTo(new CGPoint(0.4, 0.2)); path.AddLineTo(new CGPoint(0.4, 0)); var shape = SCNShape.Create(path, 0.2f); SCNNode node = new SCNNode(); node.Geometry = shape; node.Geometry.Materials = new SCNMaterial[] { material }; node.Position = new SCNVector3(0, 0, -0.7f); sceneView.Scene.RootNode.AddChildNode(node); }
public override void PresentStep(int index, PresentationViewController presentationViewController) { switch (index) { case 0: TextManager.SetSubtitle("Built-in parametric primitives"); break; case 1: PresentPrimitives(); break; case 2: // Hide the carousel and illustrate SCNText TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; SCNTransaction.SetCompletionBlock(() => { if (CarouselNode != null) { CarouselNode.RemoveFromParentNode(); } }); PresentTextNode(); TextNode.Opacity = 1.0f; if (CarouselNode != null) { CarouselNode.Position = new SCNVector3(0, CarouselNode.Position.Y, -50); CarouselNode.Opacity = 0.0f; } SCNTransaction.Commit(); TextManager.SetSubtitle("Built-in 3D text"); TextManager.AddBulletAtLevel("SCNText", 0); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.FlipInText(SlideTextManager.TextType.Bullet); break; case 3: //Show bezier path var star = StarPath(3, 6); var shape = SCNShape.Create(star, 1); shape.ChamferRadius = 0.2f; shape.ChamferProfile = OutlineChamferProfilePath(); shape.ChamferMode = SCNChamferMode.Front; // 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; outlineMaterial.DoubleSided = true; var tranparentMaterial = SCNMaterial.Create(); tranparentMaterial.Transparency = 0.0f; shape.Materials = new SCNMaterial[] { tranparentMaterial, tranparentMaterial, tranparentMaterial, outlineMaterial, outlineMaterial }; StarOutline = SCNNode.Create(); StarOutline.Geometry = shape; StarOutline.Position = new SCNVector3(0, 5, 30); StarOutline.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI * 2, 0, 10.0))); GroundNode.AddChildNode(StarOutline); // Hide the 3D text and introduce SCNShape SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1; SCNTransaction.SetCompletionBlock(() => { TextNode.RemoveFromParentNode(); }); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.SetSubtitle("3D Shapes"); TextManager.AddBulletAtLevel("SCNShape", 0); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); StarOutline.Position = new SCNVector3(0, 5, 0); TextNode.Position = new SCNVector3(TextNode.Position.X, TextNode.Position.Y, -30); SCNTransaction.Commit(); break; case 4: star = StarPath(3, 6); shape = SCNShape.Create(star, 0); shape.ChamferRadius = 0.1f; StarNode = SCNNode.Create(); StarNode.Geometry = shape; var material = SCNMaterial.Create(); material.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/color_envmap", "png")); material.Diffuse.Contents = NSColor.Black; StarNode.Geometry.Materials = new SCNMaterial[] { material }; StarNode.Position = new SCNVector3(0, 5, 0); StarNode.Pivot = SCNMatrix4.CreateTranslation(0, 0, -0.5f); StarOutline.ParentNode.AddChildNode(StarNode); StarNode.EulerAngles = StarOutline.EulerAngles; StarNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI * 2, 0, 10.0))); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; SCNTransaction.SetCompletionBlock(() => { StarOutline.RemoveFromParentNode(); }); shape.ExtrusionDepth = 1; StarOutline.Opacity = 0.0f; SCNTransaction.Commit(); break; case 5: //OpenSubdiv TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.SetSubtitle("Subdivisions"); TextManager.AddBulletAtLevel("OpenSubdiv", 0); TextManager.AddCode("#aGeometry.#SubdivisionLevel# = anInteger;#"); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); //add boxes var boxesNode = SCNNode.Create(); var level0 = Utils.SCAddChildNode(boxesNode, "rccarBody_LP", "Scenes.scnassets/car/car_lowpoly", 10); level0.Position = new SCNVector3(-6, level0.Position.Y, 0); var label = Utils.SCBoxNode("0", new CGRect(0, 0, 40, 40), NSColor.Orange, 20.0f, true); label.Position = new SCNVector3(0, -35, 10); label.Scale = new SCNVector3(0.3f, 0.3f, 0.001f); level0.AddChildNode(label); boxesNode.Position = new SCNVector3(0, 0, 30); var level1 = level0.Clone(); /*foreach (var child in level1.ChildNodes) { * if (child.Name != "engine_LP") { * child.Geometry = (SCNGeometry)child.Geometry.Copy (); * child.Geometry.SubdivisionLevel = 3; * } * }*/ level1.Position = new SCNVector3(6, level1.Position.Y, 0); boxesNode.AddChildNode(level1); label = Utils.SCBoxNode("2", new CGRect(0, 0, 40, 40), NSColor.Orange, 20.0f, true); label.Position = new SCNVector3(0, -35, 10); label.Scale = new SCNVector3(0.3f, 0.3f, 0.001f); level1.AddChildNode(label); level0.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy((float)Math.PI * 2, new SCNVector3(0, 1, 0), 45.0))); level1.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy((float)Math.PI * 2, new SCNVector3(0, 1, 0), 45.0))); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1; SCNTransaction.SetCompletionBlock(() => { StarNode.RemoveFromParentNode(); }); // move the camera back to its previous position presentationViewController.CameraNode.Position = new SCNVector3(0, 0, 0); presentationViewController.CameraPitch.Rotation = new SCNVector4(1, 0, 0, Pitch * (float)Math.PI / 180.0f); StarNode.Position = new SCNVector3(StarNode.Position.X, StarNode.Position.Y, StarNode.Position.Z - 30); StarOutline.Position = new SCNVector3(StarOutline.Position.X, StarOutline.Position.Y, StarOutline.Position.Z - 30); GroundNode.AddChildNode(boxesNode); //move boxes in boxesNode.Position = new SCNVector3(0, 0, 3.5f); SCNTransaction.Commit(); break; } }
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.scnassets/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(NMath.Cos(NMath.PI * i / 10.0f) * 20.0f, 3 + 18.5f * NMath.Sin(NMath.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); } }
public static SCNNode SCBoxNode(string title, CGRect frame, NSColor color, float cornerRadius, bool centered) { NSMutableDictionary titleAttributes = null; NSMutableDictionary centeredTitleAttributes = null; // create and extrude a bezier path to build the box var path = NSBezierPath.FromRoundedRect(frame, cornerRadius, cornerRadius); path.Flatness = 0.05f; var shape = SCNShape.Create(path, 20); shape.ChamferRadius = 0.0f; var node = SCNNode.Create(); node.Geometry = shape; // create an image and fill with the color and text var textureSize = new CGSize(); textureSize.Width = (float)Math.Ceiling((double)frame.Size.Width * 1.5); textureSize.Height = (float)Math.Ceiling((double)frame.Size.Height * 1.5); var texture = new NSImage(textureSize); texture.LockFocus(); var drawFrame = new CGRect(0, 0, textureSize.Width, textureSize.Height); nfloat hue, saturation, brightness, alpha; (color.UsingColorSpace(NSColorSpace.DeviceRGBColorSpace)).GetHsba(out hue, out saturation, out brightness, out alpha); var lightColor = NSColor.FromDeviceHsba(hue, saturation - 0.2f, brightness + 0.3f, alpha); lightColor.Set(); NSGraphics.RectFill(drawFrame); NSBezierPath fillpath = null; if (cornerRadius == 0 && centered == false) { //special case for the "labs" slide drawFrame.Offset(0, -2); fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius); } else { drawFrame.Inflate(-3, -3); fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius); } color.Set(); fillpath.Fill(); // draw the title if any if (title != null) { if (titleAttributes == null) { var paraphStyle = new NSMutableParagraphStyle(); paraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping; paraphStyle.Alignment = NSTextAlignment.Center; paraphStyle.MinimumLineHeight = 38; paraphStyle.MaximumLineHeight = 38; var font = NSFont.FromFontName("Myriad Set Semibold", 34) != null?NSFont.FromFontName("Myriad Set Semibold", 34) : NSFont.FromFontName("Avenir Medium", 34); var shadow = new NSShadow(); shadow.ShadowOffset = new CGSize(0, -2); shadow.ShadowBlurRadius = 4; shadow.ShadowColor = NSColor.FromDeviceWhite(0.0f, 0.5f); titleAttributes = new NSMutableDictionary(); titleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName); titleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName); titleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName); titleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName); var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy(); centeredParaphStyle.Alignment = NSTextAlignment.Center; centeredTitleAttributes = new NSMutableDictionary(); centeredTitleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName); centeredTitleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName); centeredTitleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName); centeredTitleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName); } var attrString = new NSAttributedString(title, centered ? centeredTitleAttributes : titleAttributes); var textSize = attrString.Size; //check if we need two lines to draw the text var twoLines = title.Contains("\n"); if (!twoLines) { twoLines = textSize.Width > frame.Size.Width && title.Contains(" "); } //if so, we need to adjust the size to center vertically if (twoLines) { textSize.Height += 38; } if (!centered) { drawFrame.Inflate(-15, 0); } //center vertically var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f; var drawFrameHeight = drawFrame.Size.Height; drawFrame.Size = new CGSize(drawFrame.Size.Width, drawFrame.Size.Height - dy); attrString.DrawString(drawFrame); } texture.UnlockFocus(); //set the created image as the diffuse texture of our 3D box var front = SCNMaterial.Create(); front.Diffuse.Contents = texture; front.LocksAmbientWithDiffuse = true; //use a lighter color for the chamfer and sides var sides = SCNMaterial.Create(); sides.Diffuse.Contents = lightColor; node.Geometry.Materials = new SCNMaterial[] { front, sides, sides, sides, sides }; return(node); }
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); }
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); }