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); }
public override void SetupSlide(PresentationViewController presentationViewController) { TextManager.SetTitle("Shadows"); TextManager.AddBulletAtLevel("Static", 0); TextManager.AddBulletAtLevel("Dynamic", 0); TextManager.AddBulletAtLevel("Projected", 0); var sceneryHolder = SCNNode.Create(); sceneryHolder.Name = "scenery"; sceneryHolder.Position = new SCNVector3(5, -19, 12); GroundNode.AddChildNode(sceneryHolder); //add scenery var scenery = Utils.SCAddChildNode(sceneryHolder, "scenery", "Scenes.scnassets/banana/level", 130); scenery.Position = new SCNVector3(-291.374969f, 1.065581f, -30.519293f); scenery.Scale = new SCNVector3(0.044634f, 0.044634f, 0.044634f); scenery.Rotation = new SCNVector4(1, 0, 0, -NMath.PI / 2); PalmTree = Utils.SCAddChildNode(GroundNode, "PalmTree", "Scenes.scnassets/palmTree/palm_tree", 15); PalmTree.Position = new SCNVector3(3, -1, 7); PalmTree.Rotation = new SCNVector4(1, 0, 0, -NMath.PI / 2); foreach (var child in PalmTree.ChildNodes) { child.CastsShadow = false; } //add a static shadow var shadowPlane = SCNNode.FromGeometry(SCNPlane.Create(15, 15)); shadowPlane.EulerAngles = new SCNVector3(-NMath.PI / 2, (float)(Math.PI / 4) * 0.5f, 0); shadowPlane.Position = new SCNVector3(0.5f, 0.1f, 2); shadowPlane.Geometry.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Images/staticShadow", "tiff")); GroundNode.AddChildNode(shadowPlane); StaticShadowNode = shadowPlane; StaticShadowNode.Opacity = 0; var character = Utils.SCAddChildNode(GroundNode, "explorer", "Scenes.scnassets/explorer/explorer_skinned", 9); var animScene = SCNScene.FromFile("Scenes.scnassets/explorer/idle"); var animatedNode = animScene.RootNode.FindChildNode("Bip001_Pelvis", true); character.AddAnimation(animatedNode.GetAnimation(animatedNode.GetAnimationKeys() [0]), new NSString("idle")); character.EulerAngles = new SCNVector3(0, NMath.PI / 2, NMath.PI / 2); character.Position = new SCNVector3(20, 0, 7); Character = character; }
private void CreateVirtualScreenNode() { SCNPlane screenGeometry = new SCNPlane { Width = 1, Height = 1 }; screenGeometry.FirstMaterial.DoubleSided = true; screenGeometry.FirstMaterial.Diffuse.Contents = UIColor.Green; virtualScreenNode = SCNNode.FromGeometry(screenGeometry); }
public LineNode() { var line = (SCNGeometry)template.Copy(NSZone.Default); line.FirstMaterial = GetNativeMaterial(style.Color); lineNode = SCNNode.FromGeometry(line); var cap = (SCNGeometry)capTemplate.Copy(NSZone.Default); cap.FirstMaterial = line.FirstMaterial; scapNode = SCNNode.FromGeometry(cap); ecapNode = SCNNode.FromGeometry(cap); AddChildNode(lineNode); AddChildNode(scapNode); AddChildNode(ecapNode); }
/// <summary> /// Creates a plane an place in on the center of the plane anchor /// and rotates so it lies flat /// </summary> private void PlaceAnchorNode(SCNNode node, ARPlaneAnchor anchor) { var plane = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z); var material = new SCNMaterial(); material.Diffuse.Contents = UIImage.FromFile("art.scnassets/PlaneGrid/grid.png"); plane.Materials = new[] { material }; plane.FirstMaterial.Transparency = 0.1f; var planeNode = SCNNode.FromGeometry(plane); planeNode.Position = new SCNVector3(anchor.Center.X, 0.0f, anchor.Center.Z); planeNode.Transform = SCNMatrix4.CreateRotationX((float)(-Math.PI / 2.0)); node.AddChildNode(planeNode); }
internal Tile(SCNPlane plane) { base.Init(); Geometry = plane; Opacity = 0F; // Create a child node with another plane of the same size, but a darker color to stand out better // This helps users see captured tiles from the back. if (ChildNodes.Length == 0) { var innerPlane = SCNPlane.Create(plane.Width, plane.Height); innerPlane.Materials = new[] { Utilities.Material(Utilities.AppBrown.ColorWithAlpha(0.8F), false, false) }; var innerNode = SCNNode.FromGeometry(innerPlane); innerNode.EulerAngles = new SCNVector3(0, (float)Math.PI, 0); AddChildNode(innerNode); } }
public Plane(ARPlaneAnchor anchor) { this.PlaneAnchor = anchor; var grid = UIImage.FromBundle("plane_grid2.png"); this.PlaneGeometry = SCNPlane.Create(PlaneAnchor.Extent.X, PlaneAnchor.Extent.Z); this.PlaneNode = SCNNode.FromGeometry(PlaneGeometry); PlaneGeometry.FirstMaterial.Transparency = 0.5f; PlaneGeometry.FirstMaterial.Diffuse.Contents = grid; PlaneNode.Transform = SCNMatrix4.CreateRotationX((float)-Math.PI / 2); PlaneNode.Position = new SCNVector3(PlaneAnchor.Center.X, 0, PlaneAnchor.Center.Z); AddChildNode(PlaneNode); }
public void CreateFloor() { var floorMaterial = new SCNMaterial(); floorMaterial.Diffuse.Contents = new UIImage("art.scnassets/Floor.jpg"); floor = SCNFloor.Create(); floor.Width = 200; floor.Length = 200; floor.FirstMaterial = floorMaterial; floor.Reflectivity = 0; floorNode = SCNNode.FromGeometry(floor); floorNode.Geometry.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Repeat; floorNode.Geometry.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Repeat; floorNode.Position = new SCNVector3(0, 0, 0); floorNode.CastsShadow = true; gameScene.RootNode.AddChildNode(floorNode); }
public void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor) { var planeAnchor = anchor as ARPlaneAnchor; if (planeAnchor == null) { return; } Console.WriteLine("didAddNode"); var text = SCNText.Create("This is a good spot", 0); text.Font = UIFont.FromName("Arial", 1); if (text.FirstMaterial != null) { text.FirstMaterial.Diffuse.Contents = UIColor.Green; } var textNode = SCNNode.FromGeometry(text); textNode.Position = new SCNVector3(-0.3f, -0.55f, 0.25f); textNode.Scale = new SCNVector3(0.075f, 0.1f, 0.5f); var plane = SCNPlane.Create(new nfloat(planeAnchor.Extent.X), new nfloat(planeAnchor.Extent.Z)); var planeNode = SCNNode.FromGeometry(plane); planeNode.Position = new SCNVector3(planeAnchor.Center.X, 0f, planeAnchor.Center.Z); var txtAngles = textNode.EulerAngles; txtAngles.X = (float)(-1f * (Math.PI / 2f)); textNode.EulerAngles = txtAngles; var planeAngles = planeNode.EulerAngles; planeAngles.X = (float)(-1f * (Math.PI / 2f)); planeNode.EulerAngles = planeAngles; planeNode.Opacity = 0.25f; node.AddChildNode(planeNode); node.AddChildNode(textNode); }
public void CreateFlagSimulationFromNode(SCNNode node) { var meshData = new ClothSimMetalNode(this.device, Width, Height); var clothNode = SCNNode.FromGeometry(meshData.Geometry); var flag = node.FindChildNode("flagStaticWave", true); if (flag != null) { var boundingBoxMax = SCNVector3.Zero; var boundingBoxMin = SCNVector3.Zero; flag.GetBoundingBox(ref boundingBoxMin, ref boundingBoxMax); var existingFlagBV = boundingBoxMax - boundingBoxMin; var rescaleToMatchSizeMatrix = SCNMatrix4.Scale(existingFlagBV.X / (float)Width); var rotation = SCNQuaternion.FromAxisAngle(SCNVector3.UnitX, (float)Math.PI / 2f); var localTransform = rescaleToMatchSizeMatrix * SCNMatrix4.Rotate(rotation.ToQuaternion()); localTransform.Transpose(); var currentTransform = SCNMatrix4.Transpose(flag.Transform); var newTransform = currentTransform * localTransform; clothNode.Transform = SCNMatrix4.Transpose(newTransform);// flag.Transform * localTransform; if (clothNode.Geometry != null) { clothNode.Geometry.FirstMaterial = flag.Geometry?.FirstMaterial; if (clothNode.Geometry.FirstMaterial != null) { clothNode.Geometry.FirstMaterial.DoubleSided = true; } } flag.ParentNode.ReplaceChildNode(flag, clothNode); clothNode.Geometry.SetupPaintColorMask("flag_flagA"); clothNode.SetPaintColors(); clothNode.FixNormalMaps(); this.clothData.Add(new ClothData(clothNode, meshData)); } }
private SCNNode CreateEyeNode() { // Create A Node To Represent The Eye var eyeGeometry = SCNCone.Create(0.005f, 0, 0.2f); eyeGeometry.RadialSegmentCount = 3; eyeGeometry.FirstMaterial.Diffuse.Contents = UIColor.Green; //eyeGeometry.FirstMaterial.Transparency = 0.5f; // Create A Holder Node & Rotate It So The Gemoetry Points Towards The Device SCNNode node = SCNNode.FromGeometry(eyeGeometry); node.EulerAngles = new SCNVector3((float)-Math.PI / 2, node.EulerAngles.Y, node.EulerAngles.Z); node.Position = new SCNVector3(node.Position.X, node.Position.Y, 0.1f); SCNNode parentNode = new SCNNode(); parentNode.AddChildNode(node); return(parentNode); }
SCNNode MakePlane(ARAnchor anchor) { var planeAchor = anchor as ARPlaneAnchor; if (planeAchor == null) { return(SCNNode.Create()); } Console.WriteLine($"MakePlane ({planeAchor})"); var geometry = SCNPlane.Create(planeAchor.Extent.X, planeAchor.Extent.Z); geometry.FirstMaterial.Diffuse.ContentColor = UIColor.Green; var gnode = SCNNode.FromGeometry(geometry); gnode.Position = new SCNVector3(planeAchor.Center.X, 0, planeAchor.Center.Z); gnode.Transform = SCNMatrix4.CreateFromAxisAngle(SCNVector3.UnitX, (float)(Math.PI / 2)); return(gnode); }
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); }
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); }
void AddPlaneNode(ARPlaneAnchor anchor, SCNNode node, NSObject contents) { var geometry = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z); var material = geometry.Materials.FirstOrDefault() ?? throw new Exception(); switch (contents) { case SCNProgram program: material.Program = program; break; default: material.Diffuse.Contents = contents; break; } var planeNode = SCNNode.FromGeometry(geometry); SceneKit.SCNMatrix4.CreateFromAxisAngle(new SCNVector3(1, 0, 0), (float)(-Math.PI / 2.0), out var m4); planeNode.Transform = m4; DispatchQueue.MainQueue.DispatchAsync(() => node.AddChildNode(planeNode)); }
public void GetBoundingBox() { using (var obj = MDLObject.FromNode(SCNNode.FromGeometry(SCNBox.Create(1, 1, 1, 0)))) { var bb = obj.GetBoundingBox(0); } }
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 override void PresentStep(int index, PresentationViewController presentationViewController) { SCNTransaction.Begin(); switch (index) { case 1: TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.SetSubtitle("API"); TextManager.AddEmptyLine(); TextManager.AddCode("#aMaterial.#ShaderModifiers# = new SCNShaderModifiers {\n" + " <Entry Point> = <GLSL Code>\n" + "};#"); TextManager.FlipInText(SlideTextManager.TextType.Code); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); break; case 2: TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.AddEmptyLine(); TextManager.AddCode("#aMaterial.#ShaderModifiers# = new SCNShaderModifiers { \n" + " EntryCGPointragment = \n" + " new Vector3 (1.0f) - #output#.Color.GetRgb () \n" + "};#"); TextManager.FlipInText(SlideTextManager.TextType.Code); break; case 3: TextManager.FlipOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.SetSubtitle("Entry points"); TextManager.AddBulletAtLevel("Geometry", 0); TextManager.AddBulletAtLevel("Surface", 0); TextManager.AddBulletAtLevel("Lighting", 0); TextManager.AddBulletAtLevel("Fragment", 0); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); break; case 4: SCNTransaction.AnimationDuration = 1; TextManager.HighlightBullet(0); // Create a (very) tesselated plane var plane = SCNPlane.Create(10, 10); plane.WidthSegmentCount = 200; plane.HeightSegmentCount = 200; // Setup the material (same as the floor) plane.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Mirror; plane.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Mirror; plane.FirstMaterial.Diffuse.Contents = new NSImage("/Library/Desktop Pictures/Circles.jpg"); plane.FirstMaterial.Diffuse.ContentsTransform = SCNMatrix4.CreateFromAxisAngle(new SCNVector3(0, 0, 1), NMath.PI / 4); plane.FirstMaterial.Specular.Contents = NSColor.White; plane.FirstMaterial.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap", "jpg")); plane.FirstMaterial.Reflective.Intensity = 0.0f; // Create a node to hold that plane PlaneNode = SCNNode.Create(); PlaneNode.Position = new SCNVector3(0, 0.1f, 0); PlaneNode.Rotation = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2)); PlaneNode.Scale = new SCNVector3(5, 5, 1); PlaneNode.Geometry = plane; ContentNode.AddChildNode(PlaneNode); // Attach the "wave" shader modifier, and set an initial intensity value of 0 var shaderFile = NSBundle.MainBundle.PathForResource("Shaders/wave", "shader"); var geometryModifier = File.ReadAllText(shaderFile); PlaneNode.Geometry.ShaderModifiers = new SCNShaderModifiers { EntryPointGeometry = geometryModifier }; PlaneNode.Geometry.SetValueForKey(new NSNumber(0.0f), new NSString("intensity")); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 0; // Show the pseudo code for the deformation var textNode = TextManager.AddCode("#float len = #geometry#.Position.Xy.Length;\n" + "aMaterial.ShaderModifiers = new SCNShaderModifiers { \n" + " #EntryPointGeometry# = geometry.Position.Y \n" + "};#"); textNode.Position = new SCNVector3(8.5f, 7, 0); SCNTransaction.Commit(); break; case 5: // Progressively increase the intensity SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 2; PlaneNode.Geometry.SetValueForKey(new NSNumber(1.0f), new NSString("intensity")); PlaneNode.Geometry.FirstMaterial.Reflective.Intensity = 0.3f; SCNTransaction.Commit(); // Redraw forever ((SCNView)presentationViewController.View).Playing = true; ((SCNView)presentationViewController.View).Loops = true; break; case 6: SCNTransaction.AnimationDuration = 1; TextManager.FadeOutText(SlideTextManager.TextType.Code); // Hide the plane used for the previous modifier PlaneNode.Geometry.SetValueForKey(new NSNumber(0.0f), new NSString("intensity")); PlaneNode.Geometry.FirstMaterial.Reflective.Intensity = 0.0f; PlaneNode.Opacity = 0.0f; // Create a sphere to illustrate the "car paint" modifier var sphere = SCNSphere.Create(6); sphere.SegmentCount = 100; sphere.FirstMaterial.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/noise", "png")); sphere.FirstMaterial.Diffuse.WrapS = SCNWrapMode.Repeat; sphere.FirstMaterial.Diffuse.WrapT = SCNWrapMode.Repeat; sphere.FirstMaterial.Reflective.Contents = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/envmap3", "jpg")); sphere.FirstMaterial.FresnelExponent = 1.3f; SphereNode = SCNNode.FromGeometry(sphere); SphereNode.Position = new SCNVector3(5, 6, 0); GroundNode.AddChildNode(SphereNode); // Attach the "car paint" shader modifier shaderFile = NSBundle.MainBundle.PathForResource("Shaders/carPaint", "shader"); var surfaceModifier = File.ReadAllText(shaderFile); sphere.FirstMaterial.ShaderModifiers = new SCNShaderModifiers { EntryPointSurface = surfaceModifier }; var rotationAnimation = CABasicAnimation.FromKeyPath("rotation"); rotationAnimation.Duration = 15.0f; rotationAnimation.RepeatCount = float.MaxValue; rotationAnimation.By = NSValue.FromVector(new SCNVector4(0, 1, 0, -(float)(Math.PI * 2))); SphereNode.AddAnimation(rotationAnimation, new NSString("sphereNodeAnimation")); TextManager.HighlightBullet(1); break; case 7: SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.5f; SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); // Move the camera closer presentationViewController.CameraNode.Position = new SCNVector3(5, -0.5f, -17); SCNTransaction.Commit(); break; case 8: SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); // Move back presentationViewController.CameraNode.Position = new SCNVector3(0, 0, 0); SCNTransaction.Commit(); break; case 9: SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; // Hide the sphere used for the previous modifier SphereNode.Opacity = 0.0f; SphereNode.Position = new SCNVector3(6, 4, -8); SCNTransaction.Commit(); SCNTransaction.AnimationDuration = 0; TextManager.HighlightBullet(2); // Load the model, animate var intermediateNode = SCNNode.Create(); intermediateNode.Position = new SCNVector3(4, 0.1f, 10); TorusNode = Utils.SCAddChildNode(intermediateNode, "torus", "Scenes/torus/torus", 11); rotationAnimation = CABasicAnimation.FromKeyPath("rotation"); rotationAnimation.Duration = 10.0f; rotationAnimation.RepeatCount = float.MaxValue; rotationAnimation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); TorusNode.AddAnimation(rotationAnimation, new NSString("torusNodeAnimation")); GroundNode.AddChildNode(intermediateNode); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; intermediateNode.Position = new SCNVector3(4, 0.1f, 0); SCNTransaction.Commit(); break; case 10: // Attach the shader modifier shaderFile = NSBundle.MainBundle.PathForResource("Shaders/toon", "shader"); var lightingModifier = File.ReadAllText(shaderFile); TorusNode.Geometry.ShaderModifiers = new SCNShaderModifiers { EntryPointLightingModel = lightingModifier }; break; case 11: SCNTransaction.AnimationDuration = 1.0f; // Hide the torus used for the previous modifier TorusNode.Position = new SCNVector3(TorusNode.Position.X, TorusNode.Position.Y, TorusNode.Position.Z - 10); TorusNode.Opacity = 0.0f; // Load the model, animate intermediateNode = SCNNode.Create(); intermediateNode.Position = new SCNVector3(4, -2.6f, 14); intermediateNode.Scale = new SCNVector3(70, 70, 70); XRayNode = Utils.SCAddChildNode(intermediateNode, "node", "Scenes/bunny", 12); XRayNode.Position = new SCNVector3(0, 0, 0); XRayNode.Opacity = 0.0f; GroundNode.AddChildNode(intermediateNode); rotationAnimation = CABasicAnimation.FromKeyPath("rotation"); rotationAnimation.Duration = 10.0f; rotationAnimation.RepeatCount = float.MaxValue; rotationAnimation.From = NSValue.FromVector(new SCNVector4(0, 1, 0, 0)); rotationAnimation.To = NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))); intermediateNode.AddAnimation(rotationAnimation, new NSString("bunnyNodeAnimation")); TextManager.HighlightBullet(3); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = 1.0f; XRayNode.Opacity = 1.0f; intermediateNode.Position = new SCNVector3(4, -2.6f, -2); SCNTransaction.Commit(); break; case 12: // Attach the "x ray" modifier shaderFile = NSBundle.MainBundle.PathForResource("Shaders/xRay", "shader"); var fragmentModifier = File.ReadAllText(shaderFile); XRayNode.Geometry.ShaderModifiers = new SCNShaderModifiers { EntryPointFragment = fragmentModifier }; XRayNode.Geometry.FirstMaterial.ReadsFromDepthBuffer = false; break; case 13: // Highlight everything TextManager.HighlightBullet(-1); // Hide the node used for the previous modifier XRayNode.Opacity = 0.0f; XRayNode.ParentNode.Position = new SCNVector3(4, -2.6f, -5); // Create the model sphere = SCNSphere.Create(5); sphere.SegmentCount = 150; // tesselate a lot VirusNode = SCNNode.FromGeometry(sphere); VirusNode.Position = new SCNVector3(3, 6, 0); VirusNode.Rotation = new SCNVector4(1, 0, 0, Pitch * (float)(Math.PI / 180.0f)); GroundNode.AddChildNode(VirusNode); // Set the shader modifiers var geomFile = NSBundle.MainBundle.PathForResource("Shaders/sm_geom", "shader"); var surfFile = NSBundle.MainBundle.PathForResource("Shaders/sm_surf", "shader"); var lightFile = NSBundle.MainBundle.PathForResource("Shaders/sm_light", "shader"); var fragFile = NSBundle.MainBundle.PathForResource("Shaders/sm_frag", "shader"); geometryModifier = File.ReadAllText(geomFile); surfaceModifier = File.ReadAllText(surfFile); lightingModifier = File.ReadAllText(lightFile); fragmentModifier = File.ReadAllText(fragFile); VirusNode.Geometry.FirstMaterial.ShaderModifiers = new SCNShaderModifiers { EntryPointGeometry = geometryModifier, EntryPointSurface = surfaceModifier, EntryPointLightingModel = lightingModifier, EntryPointFragment = fragmentModifier }; break; case 14: SCNTransaction.AnimationDuration = 1.0f; // Hide the node used for the previous modifier VirusNode.Opacity = 0.0f; VirusNode.Position = new SCNVector3(3, 6, -10); // Change the text TextManager.FadeOutText(SlideTextManager.TextType.Code); TextManager.FlipOutText(SlideTextManager.TextType.Bullet); TextManager.FlipOutText(SlideTextManager.TextType.Subtitle); TextManager.SetSubtitle("SCNShadable"); TextManager.AddBulletAtLevel("Protocol adopted by SCNMaterial and SCNGeometry", 0); TextManager.AddBulletAtLevel("Shaders parameters are animatable", 0); TextManager.AddBulletAtLevel("Texture samplers are bound to a SCNMaterialProperty", 0); TextManager.AddCode("#var aProperty = SCNMaterialProperty.#Create# (anImage);\n" + "aMaterial.#SetValueForKey# (aProperty, #new NSString# (\"aSampler\"));#"); TextManager.FlipInText(SlideTextManager.TextType.Subtitle); TextManager.FlipInText(SlideTextManager.TextType.Bullet); TextManager.FlipInText(SlideTextManager.TextType.Code); break; } SCNTransaction.Commit(); }
internal ObjectOriginAxis(Axis axis, float length, float thickness, float radius, float handleSize) { this.axis = axis; base.Init(); UIColor color = default(UIColor); UIImage texture = default(UIImage); SCNVector3 dimensions = default(SCNVector3); var position = new SCNVector3((float)(axis.Normal().X *(length / 2.0)), (float)(axis.Normal().Y *(length / 2.0)), (float)(axis.Normal().Z *(length / 2.0))); var axisHandlePosition = new SCNVector3((float)(axis.Normal().X *length), (float)(axis.Normal().Y *length), (float)(axis.Normal().Z *length)); switch (axis) { case Axis.X: color = UIColor.Red; texture = UIImage.FromFile("handle_red"); dimensions = new SCNVector3(length, thickness, thickness); break; case Axis.Y: color = UIColor.Green; texture = UIImage.FromFile("handle_green"); dimensions = new SCNVector3(thickness, length, thickness); break; case Axis.Z: color = UIColor.Blue; texture = UIImage.FromFile("handle_blue"); dimensions = new SCNVector3(thickness, thickness, length); break; } var axisGeo = SCNBox.Create(dimensions.X, dimensions.Y, dimensions.Z, radius); axisGeo.Materials = new[] { Utilities.Material(color) }; var axisNode = SCNNode.FromGeometry(axisGeo); var axisHandleGeo = SCNPlane.Create(handleSize, handleSize); axisHandleGeo.Materials = new[] { Utilities.Material(texture, false) }; var axisHandle = SCNNode.FromGeometry(axisHandleGeo); axisHandle.Constraints = new[] { new SCNBillboardConstraint() }; axisNode.Position = position; axisHandle.Position = axisHandlePosition; // Increase the axis handle geometry's bounding box that is used for hit testing to make it easier to hit SCNVector3 min = default(SCNVector3); SCNVector3 max = default(SCNVector3); axisHandle.GetBoundingBox(ref min, ref max); var padding = handleSize * 0.8F; var newMin = new SCNVector3(min.X - padding, min.Y - padding, min.Z - padding); var newMax = new SCNVector3(max.X + padding, max.Y + padding, max.Z + padding); axisHandle.SetBoundingBox(ref newMin, ref newMax); AddChildNode(axisNode); AddChildNode(axisHandle); }
public static SCNNode ToSCNNode(this Solid csg) { return(SCNNode.FromGeometry(csg.ToSCNGeometry())); }